Skip to content

Commit 20f0cef

Browse files
Version 1.x (#29)
- drop support php < 7.2 - update phpunit to 7.5 - add strict types in all files - add return type and argument type hinting in all files - bump copyright to 2019
1 parent 54ed942 commit 20f0cef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+588
-362
lines changed

.gitattributes

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.gitattributes export-ignore
2+
.gitignore export-ignore
3+
.scrutinizer.yml export-ignore
4+
.travis.coverage.sh export-ignore
5+
.travis.yml export-ignore
6+
phpcs.xml.dist export-ignore
7+
phpunit.xml.dist export-ignore
8+
phpstan.xml.dist export-ignore

.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
/vendor/
1+
# Composer
2+
vendor/
23
composer.lock
4+
5+
# Cache
36
/tests/cache/
47
/demo/cache/
8+
9+
# Code quality
10+
/phpunit.xml
11+
/phpcs.xml
12+
/phpstan.neon

.scrutinizer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ tools:
99
php_code_sniffer:
1010
enabled: true
1111
config:
12-
standard: PSR2
12+
standard: PSR12
1313
filter:
1414
paths: ["src/*"]
1515
php_cpd:

.travis.coverage.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set -x
2-
if [ "$TRAVIS_PHP_VERSION" = '7.0' ] ; then
2+
if [ "$TRAVIS_PHP_VERSION" = '7.2' ] ; then
33
wget https://scrutinizer-ci.com/ocular.phar
44
php ocular.phar code-coverage:upload --format=php-clover ./clover.xml
55
fi

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
language: php
22

33
php:
4-
- 7.0
5-
- 7.1
64
- 7.2
5+
- 7.3
76

87
before_script:
98
- composer install
109

1110
script:
1211
- vendor/bin/phpunit --verbose --coverage-text --coverage-clover=clover.xml --colors
12+
- vendor/bin/phpcs src/ tests/
13+
- vendor/bin/phpstan analyze
1314

1415
after_script:
1516
- sh .travis.coverage.sh

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ break a caller, C++ FAQs uses the memorable phrase "require no more, promise no
2323
does not require more from the caller than before, and if it does not promise to deliver less than before,
2424
then the new specification is compatible with the old, and will not break the caller.
2525

26-
[![Build Status](https://api.travis-ci.org/php-deal/framework.png?branch=master)](https://travis-ci.org/php-deal/framework)
26+
[![Build Status](https://api.travis-ci.org/php-deal/framework.png?branch=1.x)](https://travis-ci.org/php-deal/framework)
2727
[![GitHub release](https://img.shields.io/github/release/php-deal/framework.svg)](https://github.com/php-deal/framework/releases/latest)
28-
[![Code Coverage](https://scrutinizer-ci.com/g/php-deal/framework/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/php-deal/framework/?branch=master)
29-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/php-deal/framework/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/php-deal/framework/?branch=master)
30-
[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg)](https://php.net/)
28+
[![Code Coverage](https://scrutinizer-ci.com/g/php-deal/framework/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/php-deal/framework/?branch=1.x)
29+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/php-deal/framework/badges/quality-score.png?b=1.x)](https://scrutinizer-ci.com/g/php-deal/framework/?branch=1.x)
30+
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D7.2-blue.svg)](https://php.net/)
3131
[![License](https://img.shields.io/packagist/l/php-deal/framework.svg)](https://packagist.org/packages/php-deal/framework)
3232

3333
Installation
@@ -148,16 +148,16 @@ There a some differences in inheritance of the contracts:
148148
- if provided `Ensure` will automatically inherit all contracts from parent class or interface
149149
2. Verify
150150
- if provided `Verify` will _not_ inherit contracts from parent class or interface
151-
- to inherit contracts you will ne to provide `@inheritdoc` or the `Inherit` contract
151+
- to inherit contracts you will need to provide `@inheritdoc` or the `Inherit` contract
152152
3. Invariant
153153
- if provided `Invariant` will inherit all contracts from parent class or interface
154154
4. Inherit
155-
- if provided `Inherit` will inherit all contracts from the given leven (class, method) without the
155+
- if provided `Inherit` will inherit all contracts from the given level (class, method) without the
156156
need to provide a contract on your current class or method
157157

158158
__Notes__:
159159
- The parsing of a contract only happens __IF__ you provide any given annotation from this package.
160-
Without it your contracts won't work!
160+
Without it, your contracts won't work!
161161
- The annotation __must not__ have curly braces (`{}`) otherwise the annotation reader can't find them.
162162

163163
```php

composer.json

+39-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
"name": "php-deal/framework",
33
"description": "Design by Contract framework for PHP",
44
"require": {
5-
"php": "~7.0",
6-
"goaop/framework": "~2.0"
5+
"php": "^7.2",
6+
"goaop/framework": "^2.3"
77
},
88
"require-dev": {
9-
"symfony/console": "~2.7|~3.0",
10-
"phpunit/phpunit": "^5.7",
11-
"beberlei/assert": "~3.0"
9+
"beberlei/assert": "~3.0",
10+
"phpstan/phpstan": "^0.11.0",
11+
"phpunit/phpunit": "^7.5",
12+
"roave/security-advisories": "dev-master",
13+
"slevomat/coding-standard": "^4.8",
14+
"squizlabs/php_codesniffer": "^3.4",
15+
"symfony/console": "~2.7|~3.0|~4.0"
1216
},
1317
"license": "MIT",
1418
"authors": [
@@ -19,21 +23,44 @@
1923
{
2024
"name": "Piotr Dawidiuk",
2125
"email": "[email protected]"
26+
},
27+
{
28+
"name": "Andreas Frömer",
29+
"email": "[email protected]"
2230
}
2331
],
2432
"autoload": {
25-
"psr-4": {"PhpDeal\\": "src/"}
33+
"psr-4": {
34+
"PhpDeal\\": "src/"
35+
}
2636
},
2737
"autoload-dev": {
28-
"psr-0": {"Demo\\": "demo/"},
29-
"psr-4": {"PhpDeal\\": "tests/"}
38+
"psr-0": {
39+
"Demo\\": "demo/"
40+
},
41+
"psr-4": {
42+
"PhpDeal\\": "tests/"
43+
}
44+
},
45+
"scripts": {
46+
"phpstan": "phpstan analyze",
47+
"phpcs": "phpcs src tests -sp --colors",
48+
"phpunit": "phpunit --verbose --colors=always",
49+
"test": [
50+
"@phpstan",
51+
"@phpcs",
52+
"@phpunit"
53+
]
54+
},
55+
"config": {
56+
"sort-packages": true
3057
},
3158
"suggest": {
32-
"beberlei/assert": "Thin assertion library for input validation in business models. Used for tests."
59+
"beberlei/assert": "Thin assertion library for input validation in business models. Used for tests."
3360
},
3461
"support": {
35-
"issues": "https://github.com/php-deal/framework/issues",
36-
"source": "https://github.com/php-deal/framework",
37-
"docs": "https://github.com/php-deal/framework/blob/master/README.md"
62+
"issues": "https://github.com/php-deal/framework/issues",
63+
"source": "https://github.com/php-deal/framework",
64+
"docs": "https://github.com/php-deal/framework/blob/master/README.md"
3865
}
3966
}

demo/Demo/Account.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Deal framework
46
*
5-
* @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
7+
* @copyright Copyright 2019, Lisachenko Alexander <[email protected]>
68
*
79
* This source file is subject to the license that is bundled
810
* with this source code in the file LICENSE.

demo/Demo/AccountContractInterface.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Deal framework
46
*
5-
* @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
7+
* @copyright Copyright 2019, Lisachenko Alexander <[email protected]>
68
*
79
* This source file is subject to the license that is bundled
810
* with this source code in the file LICENSE.

demo/aspect_bootstrap.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Deal framework
46
*
5-
* @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
7+
* @copyright Copyright 2019, Lisachenko Alexander <[email protected]>
68
*
79
* This source file is subject to the license that is bundled
810
* with this source code in the file LICENSE.

demo/demo.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Deal framework
46
*
5-
* @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
7+
* @copyright Copyright 2019, Lisachenko Alexander <[email protected]>
68
*
79
* This source file is subject to the license that is bundled
810
* with this source code in the file LICENSE.
@@ -18,6 +20,6 @@
1820
$account->deposit(100);
1921
echo 'Current balance: ' . $account->getBalance();
2022
echo PHP_EOL;
21-
echo 'Withdraw: 100' . PHP_EOL;
23+
echo 'Withdraw: 50' . PHP_EOL;
2224
$account->withdraw(50);
2325
echo 'Current balance: ' . $account->getBalance();

phpcs.xml.dist

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PSR12-phpdeal">
3+
<description>PSR-12 with native function invocation</description>
4+
<!-- Add slevomat/coding-standard to installed_paths so we can use a single sniff -->
5+
<config name="installed_paths" value="../../slevomat/coding-standard"/>
6+
7+
<exclude-pattern>*/cache</exclude-pattern>
8+
9+
<rule ref="PSR12"/>
10+
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions"/>
11+
</ruleset>

phpstan.neon.dist

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
excludes_analyse:
3+
- %rootDir%/../../../tests/cache
4+
level: max
5+
paths:
6+
- src/
7+
- tests/

phpunit.xml.dist

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
bootstrap="./tests/bootstrap.php"
1312
>
1413
<php>

src/Annotation/Ensure.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Deal framework
46
*
5-
* @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
7+
* @copyright Copyright 2019, Lisachenko Alexander <[email protected]>
68
*
79
* This source file is subject to the license that is bundled
810
* with this source code in the file LICENSE.
@@ -19,7 +21,7 @@
1921
*/
2022
class Ensure extends BaseAnnotation
2123
{
22-
public function __toString()
24+
public function __toString(): string
2325
{
2426
return $this->value;
2527
}

src/Annotation/Invariant.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Deal framework
46
*
5-
* @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
7+
* @copyright Copyright 2019, Lisachenko Alexander <[email protected]>
68
*
79
* This source file is subject to the license that is bundled
810
* with this source code in the file LICENSE.
@@ -19,7 +21,7 @@
1921
*/
2022
class Invariant extends BaseAnnotation
2123
{
22-
public function __toString()
24+
public function __toString(): string
2325
{
2426
return $this->value;
2527
}

src/Annotation/Verify.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Deal framework
46
*
5-
* @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
7+
* @copyright Copyright 2019, Lisachenko Alexander <[email protected]>
68
*
79
* This source file is subject to the license that is bundled
810
* with this source code in the file LICENSE.

src/Aspect/AbstractContractAspect.php

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Deal framework
46
*
5-
* @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
7+
* @copyright Copyright 2019, Lisachenko Alexander <[email protected]>
68
*
79
* This source file is subject to the license that is bundled
810
* with this source code in the file LICENSE.
@@ -36,22 +38,22 @@ public function __construct(Reader $reader)
3638
*
3739
* @param MethodInvocation $invocation
3840
* @return array
41+
* @throws \ReflectionException
3942
*/
40-
protected function fetchMethodArguments(MethodInvocation $invocation)
43+
protected function fetchMethodArguments(MethodInvocation $invocation): array
4144
{
4245
$result = [];
4346
$parameters = $invocation->getMethod()->getParameters();
4447
$argumentValues = $invocation->getArguments();
4548

4649
// Number of arguments can be less than number of parameters because of default values
4750
foreach ($parameters as $parameterIndex => $reflectionParameter) {
48-
$hasArgumentValue = array_key_exists($parameterIndex, $argumentValues);
51+
$hasArgumentValue = \array_key_exists($parameterIndex, $argumentValues);
4952
$argumentValue = $hasArgumentValue ? $argumentValues[$parameterIndex] : null;
5053
if (!$hasArgumentValue && $reflectionParameter->isDefaultValueAvailable()) {
5154
$argumentValue = $reflectionParameter->getDefaultValue();
5255
}
5356
$result[$reflectionParameter->name] = $argumentValue;
54-
5557
}
5658

5759
return $result;
@@ -69,28 +71,34 @@ protected function fetchMethodArguments(MethodInvocation $invocation)
6971
* @throws DomainException
7072
* @throws ContractViolation
7173
*/
72-
protected function ensureContracts(MethodInvocation $invocation, array $contracts, $instance, $scope, array $args)
73-
{
74+
protected function ensureContracts(
75+
MethodInvocation $invocation,
76+
array $contracts,
77+
$instance,
78+
string $scope,
79+
array $args
80+
): void {
7481
static $invoker = null;
7582
if (!$invoker) {
7683
$invoker = function () {
77-
extract(func_get_arg(0));
84+
$args = \func_get_arg(0);
85+
\extract($args, EXTR_OVERWRITE);
7886

79-
return eval('return ' . func_get_arg(1) . '; ?>');
87+
return eval('return ' . \func_get_arg(1) . '; ?>');
8088
};
8189
}
8290

83-
$instance = is_object($instance) ? $instance : null;
91+
$instance = \is_object($instance) ? $instance : null;
8492
$boundInvoker = $invoker->bindTo($instance, $scope);
8593

8694
foreach ($contracts as $contract) {
8795
$contractExpression = $contract->value;
8896
try {
8997
$invocationResult = $boundInvoker->__invoke($args, $contractExpression);
9098

91-
// if ($invocationResult === false) {
92-
// throw new ContractViolation($invocation, $contractExpression);
93-
// }
99+
if ($invocationResult === false) {
100+
throw new ContractViolation($invocation, $contractExpression);
101+
}
94102

95103
// we accept as a result only true or null
96104
// null may be a result of assertions from beberlei/assert which passed
@@ -99,7 +107,6 @@ protected function ensureContracts(MethodInvocation $invocation, array $contract
99107
. ' only boolean or void can be returned';
100108
throw new DomainException($errorMessage);
101109
}
102-
103110
} catch (\Error $internalError) {
104111
// PHP-7 friendly interceptor for fatal errors
105112
throw new ContractViolation($invocation, $contractExpression, $internalError);

0 commit comments

Comments
 (0)