Skip to content

Commit 603a4a6

Browse files
committed
Add contracts support
1 parent b734b50 commit 603a4a6

33 files changed

+303
-479
lines changed

.github/workflows/main.yml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: build
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 0 * * *'
8+
9+
env:
10+
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
11+
12+
jobs:
13+
security:
14+
name: Security
15+
runs-on: ${{ matrix.os }}
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
php: [ '8.1' ]
21+
os: [ ubuntu-latest ]
22+
23+
steps: # General Steps
24+
- name: Set Git To Use LF
25+
run: |
26+
git config --global core.autocrlf false
27+
git config --global core.eol lf
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
31+
# Install PHP Dependencies
32+
- name: Setup PHP ${{ matrix.php }}
33+
uses: shivammathur/setup-php@v2
34+
with:
35+
php-version: ${{ matrix.php }}
36+
- name: Validate Composer
37+
run: composer validate
38+
- name: Get Composer Cache Directory
39+
# Docs: <https://github.com/actions/cache/blob/master/examples.md#php---composer>
40+
id: composer-cache
41+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
42+
- name: Restore Composer Cache
43+
uses: actions/cache@v1
44+
with:
45+
path: ${{ steps.composer-cache.outputs.dir }}
46+
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
47+
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer-
48+
- name: Install Dependencies
49+
uses: nick-invision/retry@v1
50+
with:
51+
timeout_minutes: 5
52+
max_attempts: 5
53+
command: composer update --prefer-dist --no-interaction --no-progress
54+
55+
# Execution
56+
- name: Security Advisories
57+
run: composer require --dev roave/security-advisories:dev-latest
58+
59+
static-analysis:
60+
name: Psalm
61+
runs-on: ${{ matrix.os }}
62+
63+
strategy:
64+
fail-fast: false
65+
matrix:
66+
php: [ '7.4', '8.0', '8.1' ]
67+
os: [ ubuntu-latest ]
68+
69+
steps: # General Steps
70+
- name: Set Git To Use LF
71+
run: |
72+
git config --global core.autocrlf false
73+
git config --global core.eol lf
74+
- name: Checkout
75+
uses: actions/checkout@v2
76+
77+
# Install PHP Dependencies
78+
- name: Setup PHP ${{ matrix.php }}
79+
uses: shivammathur/setup-php@v2
80+
with:
81+
php-version: ${{ matrix.php }}
82+
- name: Validate Composer
83+
run: composer validate
84+
- name: Get Composer Cache Directory
85+
# Docs: <https://github.com/actions/cache/blob/master/examples.md#php---composer>
86+
id: composer-cache
87+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
88+
- name: Restore Composer Cache
89+
uses: actions/cache@v1
90+
with:
91+
path: ${{ steps.composer-cache.outputs.dir }}
92+
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
93+
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer-
94+
- name: Install Dependencies
95+
uses: nick-invision/retry@v1
96+
with:
97+
timeout_minutes: 5
98+
max_attempts: 5
99+
command: composer update --prefer-dist --no-interaction --no-progress
100+
101+
# Execution
102+
- name: Static Analysis
103+
continue-on-error: true
104+
run: vendor/bin/psalm --no-cache
105+
106+
coding-standards:
107+
name: Coding Standards
108+
runs-on: ${{ matrix.os }}
109+
110+
strategy:
111+
fail-fast: false
112+
matrix:
113+
php: [ '8.1' ]
114+
os: [ ubuntu-latest ]
115+
116+
steps: # General Steps
117+
- name: Set Git To Use LF
118+
run: |
119+
git config --global core.autocrlf false
120+
git config --global core.eol lf
121+
- name: Checkout
122+
uses: actions/checkout@v2
123+
124+
# Install PHP Dependencies
125+
- name: Setup PHP ${{ matrix.php }}
126+
uses: shivammathur/setup-php@v2
127+
with:
128+
php-version: ${{ matrix.php }}
129+
- name: Validate Composer
130+
run: composer validate
131+
- name: Get Composer Cache Directory
132+
# Docs: <https://github.com/actions/cache/blob/master/examples.md#php---composer>
133+
id: composer-cache
134+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
135+
- name: Restore Composer Cache
136+
uses: actions/cache@v1
137+
with:
138+
path: ${{ steps.composer-cache.outputs.dir }}
139+
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
140+
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer-
141+
- name: Install Dependencies
142+
uses: nick-invision/retry@v1
143+
with:
144+
timeout_minutes: 5
145+
max_attempts: 5
146+
command: composer update --prefer-dist --no-interaction --no-progress
147+
148+
# Execution
149+
- name: Check Coding Standards
150+
run: vendor/bin/phpcs --standard=phpcs.xml

composer.json

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
],
2020
"require": {
2121
"php": ">=7.4",
22+
"ffi/preprocessor-contracts": "^1.0",
2223
"psr/log": "^1.0|^2.0|^3.0",
2324
"phplrt/parser": "^3.1",
2425
"phplrt/lexer": "^3.1",
25-
"symfony/polyfill-php80": "^1.23",
26-
"symfony/polyfill-ctype": "^1.23"
26+
"symfony/polyfill-php80": "^1.24",
27+
"symfony/polyfill-ctype": "^1.24"
2728
},
2829
"autoload": {
2930
"psr-4": {
@@ -32,17 +33,32 @@
3233
},
3334
"require-dev": {
3435
"jetbrains/phpstorm-attributes": "^1.0",
35-
"phpunit/phpunit": "^9.0",
36+
"phpunit/phpunit": "^9.5",
3637
"monolog/monolog": "^2.3",
37-
"phplrt/phplrt": "^3.1"
38+
"phplrt/phplrt": "^3.1",
39+
"vimeo/psalm": "^4.21",
40+
"squizlabs/php_codesniffer": "^3.6"
3841
},
3942
"autoload-dev": {
4043
"psr-4": {
4144
"FFI\\Preprocessor\\Tests\\": "tests"
4245
}
4346
},
4447
"config": {
45-
"sort-packages": true
48+
"sort-packages": true,
49+
"allow-plugins": {
50+
"composer/package-versions-deprecated": true
51+
}
52+
},
53+
"provide": {
54+
"ffi/preprocessor-contracts-implementation": "^1.0"
55+
},
56+
"scripts": {
57+
"test": [
58+
"psalm --no-cache",
59+
"phpcs --standard=phpcs.xml",
60+
"phpunit --testdox"
61+
]
4662
},
4763
"extra": {
4864
"branch-alias": {

phpcs.xml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Code Style Ruleset">
3+
<!-- config -->
4+
<rule ref="PSR12">
5+
<exclude name="PSR12.Classes.AnonClassDeclaration"/>
6+
</rule>
7+
<rule ref="Generic.PHP.ForbiddenFunctions">
8+
<properties>
9+
<property name="forbiddenFunctions" type="array" extend="true">
10+
<!-- deprecated/aliased functions -->
11+
<element key="join" value="implode" />
12+
<element key="chop" value="rtrim" />
13+
<element key="strchr" value="strstr" />
14+
<element key="show_source" value="highlight_file" />
15+
<element key="ini_alter" value="ini_set" />
16+
<element key="dns_check_record" value="checkdnsrr" />
17+
<element key="dns_get_mx" value="getmxrr" />
18+
<element key="doubleval" value="floatval" />
19+
<element key="is_long" value="is_int" />
20+
<element key="is_integer" value="is_int" />
21+
<element key="is_double" value="is_float" />
22+
<element key="is_real" value="is_float" />
23+
<element key="fputs" value="fwrite" />
24+
<element key="set_file_buffer" value="stream_set_write_buffer" />
25+
<element key="set_socket_blocking" value="stream_set_blocking" />
26+
<element key="socket_set_blocking" value="stream_set_blocking" />
27+
<element key="stream_register_wrapper" value="stream_wrapper_register" />
28+
<element key="socket_set_timeout" value="stream_set_timeout" />
29+
<element key="socket_get_status" value="stream_get_meta_data" />
30+
<element key="is_writeable" value="is_writable" />
31+
<element key="pos" value="current" />
32+
<element key="sizeof" value="count" />
33+
34+
<!-- deprecated/aliased operators -->
35+
<element key="delete" value="unset" />
36+
<element key="print" value="echo" />
37+
<element key="create_function" value="null" />
38+
</property>
39+
</properties>
40+
</rule>
41+
42+
<arg name="colors"/>
43+
44+
<!-- includes -->
45+
<file>./src</file>
46+
</ruleset>

psalm.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="1"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns="https://getpsalm.org/schema/config"
6+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
7+
>
8+
<projectFiles>
9+
<directory name="src" />
10+
<ignoreFiles>
11+
<directory name="vendor" />
12+
</ignoreFiles>
13+
</projectFiles>
14+
</psalm>

src/Directive/Directive.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace FFI\Preprocessor\Directive;
1313

14-
abstract class Directive implements DirectiveInterface
14+
use FFI\Contracts\Preprocessor\Directive\FunctionLikeDirectiveInterface;
15+
16+
abstract class Directive implements FunctionLikeDirectiveInterface
1517
{
1618
/**
1719
* @var string

src/Directive/DirectiveInterface.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/Directive/ProviderInterface.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Directive/RegistrarInterface.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Directive/Repository.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111

1212
namespace FFI\Preprocessor\Directive;
1313

14+
use FFI\Contracts\Preprocessor\Directive\DirectiveInterface;
15+
use FFI\Contracts\Preprocessor\Directive\RegistrarInterface;
16+
use FFI\Contracts\Preprocessor\Directive\RepositoryInterface;
1417
use FFI\Preprocessor\Exception\DirectiveDefinitionException;
1518

16-
final class Repository implements RepositoryInterface, RegistrarInterface
19+
final class Repository implements RepositoryInterface, RegistrarInterface, \IteratorAggregate
1720
{
1821
/**
1922
* @var array<string, DirectiveInterface>

0 commit comments

Comments
 (0)