Skip to content

Commit a8173ec

Browse files
committed
adding a coding static analysis tools with PHPStan
1 parent 0388188 commit a8173ec

16 files changed

+90
-48
lines changed

.gitattributes

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
* text=auto
22

3-
/.editorconfig export-ignore
4-
/.gitattributes export-ignore
5-
/.github export-ignore
6-
/.gitignore export-ignore
7-
/.php_cs export-ignore
8-
/.travis.yml export-ignore
9-
/README.md export-ignore
10-
/CHANGELOG.md export-ignore
11-
/phpunit.xml.dist export-ignore
12-
/tests export-ignore
3+
/.editorconfig export-ignore
4+
/.gitattributes export-ignore
5+
/.github export-ignore
6+
/.gitignore export-ignore
7+
/.php_cs export-ignore
8+
/.phpstan.src.neon export-ignore
9+
/.phpstan.tests.neon export-ignore
10+
/.travis.yml export-ignore
11+
/README.md export-ignore
12+
/phpunit.xml.dist export-ignore
13+
/tests export-ignore

.travis.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ sudo: false
55
matrix:
66
include:
77
- php: 7.0
8-
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=true IGNORE_PLATFORMS=false
8+
env: VALIDATE_CODING_STYLE=false RUN_PHPSTAN=false IGNORE_PLATFORMS=false
99
- php: 7.1
10-
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=true IGNORE_PLATFORMS=false
10+
env: VALIDATE_CODING_STYLE=false RUN_PHPSTAN=false IGNORE_PLATFORMS=false
1111
- php: 7.2
12-
env: COLLECT_COVERAGE=false VALIDATE_CODING_STYLE=false IGNORE_PLATFORMS=true
12+
env: VALIDATE_CODING_STYLE=true RUN_PHPSTAN=true IGNORE_PLATFORMS=false
1313
- php: nightly
14-
env: COLLECT_COVERAGE=false VALIDATE_CODING_STYLE=false IGNORE_PLATFORMS=true
14+
env: VALIDATE_CODING_STYLE=false RUN_PHPSTAN=false IGNORE_PLATFORMS=true
1515
allow_failures:
1616
- php: nightly
1717
fast_finish: true
@@ -31,5 +31,5 @@ script:
3131
- composer phpunit
3232

3333
after_script:
34-
- if [ "$COLLECT_COVERAGE" == "true" ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/clover.xml; fi
35-
- if [ "$VALIDATE_CODING_STYLE" == "true" ]; then composer phpcs; fi
34+
- if [ "$VALIDATE_CODING_STYLE" == "true" ]; then composer phpcs; fi
35+
- if [ "$RUN_PHPSTAN" == "true" ]; then composer phpstan; fi

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All Notable changes to `PHP Domain Parser` **5.x** series will be documented in this file
44

5-
## Next - TBD
5+
## 5.2.0 - 2018-02-23
66

77
### Added
88

@@ -17,7 +17,8 @@ All Notable changes to `PHP Domain Parser` **5.x** series will be documented in
1717

1818
- `Pdp\Domain::getDomain` returns the normalized form of the domain name
1919
- `Pdp\PublicSuffix` is no longer internal.
20-
- normalizes IDN conversion using a internal `IDNConverterTrait`
20+
- Normalizes IDN conversion using a internal `IDNConverterTrait`
21+
- Internal code improved by requiring PHPStan for development
2122

2223
### Deprecated
2324

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,26 @@ Contributing
428428

429429
Contributions are welcome and will be fully credited. Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
430430

431+
Testing
432+
-------
433+
434+
`pdp-domain-parser` has:
435+
436+
- a [PHPUnit](https://phpunit.de) test suite
437+
- a coding style compliance test suite using [PHP CS Fixer](http://cs.sensiolabs.org/).
438+
- a code analysis compliance test suite using [PHPStan](https://github.com/phpstan/phpstan).
439+
440+
To run the tests, run the following command from the project folder.
441+
442+
``` bash
443+
$ composer test
444+
```
445+
446+
Security
447+
-------
448+
449+
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
450+
431451
Credits
432452
-------
433453

composer.json

+19-5
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@
3939
"psr/simple-cache": "^1"
4040
},
4141
"require-dev": {
42-
"phpunit/phpunit": "^6.3",
42+
"composer/composer": "^1.6",
43+
"friendsofphp/php-cs-fixer": "^2.7",
4344
"mikey179/vfsStream": "^1.6",
44-
"friendsofphp/php-cs-fixer": "^2.7"
45+
"phpstan/phpstan": "^0.9.2",
46+
"phpstan/phpstan-phpunit": "^0.9.4",
47+
"phpstan/phpstan-strict-rules": "^0.9.0",
48+
"phpunit/phpunit": "^6.3"
4549
},
4650
"suggest": {
4751
"psr/simple-cache-implementation": "To enable using other cache providers",
@@ -59,11 +63,21 @@
5963
}
6064
},
6165
"scripts": {
66+
"phpcs": "php-cs-fixer fix -vv --diff --dry-run --allow-risky=yes",
67+
"phpstan-src": "phpstan analyse -l 7 -c phpstan.src.neon src",
68+
"phpstan-tests": "phpstan analyse -l 7 -c phpstan.tests.neon tests",
69+
"phpstan": [
70+
"@phpstan-src",
71+
"@phpstan-tests"
72+
],
73+
"phpunit": "phpunit --coverage-text",
6274
"post-install-cmd": "\\Pdp\\Installer::updateLocalCache",
6375
"post-update-cmd": "\\Pdp\\Installer::updateLocalCache",
64-
"test": "phpunit --coverage-text; php-cs-fixer fix -vv --diff --dry-run --allow-risky=yes",
65-
"phpunit": "phpunit --coverage-text",
66-
"phpcs": "php-cs-fixer fix -vv --diff --dry-run --allow-risky=yes"
76+
"test": [
77+
"@phpunit",
78+
"@phpcs",
79+
"@phpstan"
80+
]
6781
},
6882
"extra": {
6983
"branch-alias": {

data/pdp-PSL_FULL_5a3cc7f81795bb2e48e848af42d287b4.cache

+1-1
Large diffs are not rendered by default.

phpstan.src.neon

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
includes:
2+
- vendor/phpstan/phpstan-strict-rules/rules.neon
3+
parameters:
4+
ignoreErrors:
5+
- '#has invalid typehint type Psr\\SimpleCache\\DateInterval#'
6+
reportUnmatchedIgnoredErrors: false

phpstan.tests.neon

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
includes:
2+
- vendor/phpstan/phpstan-strict-rules/rules.neon
3+
- vendor/phpstan/phpstan-phpunit/extension.neon
4+
- vendor/phpstan/phpstan-phpunit/rules.neon
5+
- vendor/phpstan/phpstan-phpunit/strictRules.neon

src/Installer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static function updateLocalCache(Event $event = null)
6767
$io->writeError([
6868
'😓 😓 😓 Your local cache could not be updated. 😓 😓 😓',
6969
'An error occurred during the update.',
70-
'----- Error Trace ----',
70+
'----- Error Message ----',
7171
]);
7272
$io->writeError($e->getMessage());
7373
die(1);
@@ -83,7 +83,7 @@ public static function updateLocalCache(Event $event = null)
8383
*/
8484
private static function getVendorPath(Event $event = null)
8585
{
86-
if ($event instanceof Event) {
86+
if (null !== $event) {
8787
return $event->getComposer()->getConfig()->get('vendor-dir');
8888
}
8989

@@ -103,11 +103,11 @@ private static function getVendorPath(Event $event = null)
103103
*
104104
* @param Event|null $event
105105
*
106-
* @return object
106+
* @return mixed
107107
*/
108108
private static function getIO(Event $event = null)
109109
{
110-
if ($event instanceof Event) {
110+
if (null !== $event) {
111111
return $event->getIO();
112112
}
113113

src/Rules.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function __construct(array $rules)
102102
*/
103103
public function getPublicSuffix(string $domain = null, string $section = self::ALL_DOMAINS): PublicSuffix
104104
{
105-
if (!$this->isMatchable($domain)) {
105+
if (null === $domain || !$this->isMatchable($domain)) {
106106
throw new Exception(sprintf('The submitted domain `%s` is invalid or malformed', $domain));
107107
}
108108
$this->validateSection($section);
@@ -121,7 +121,7 @@ public function getPublicSuffix(string $domain = null, string $section = self::A
121121
public function resolve(string $domain = null, string $section = self::ALL_DOMAINS): Domain
122122
{
123123
$this->validateSection($section);
124-
if (!$this->isMatchable($domain)) {
124+
if (null === $domain || !$this->isMatchable($domain)) {
125125
return new Domain();
126126
}
127127

@@ -135,14 +135,13 @@ public function resolve(string $domain = null, string $section = self::ALL_DOMAI
135135
/**
136136
* Tells whether the given domain can be resolved.
137137
*
138-
* @param string|null $domain
138+
* @param string $domain
139139
*
140140
* @return bool
141141
*/
142142
private function isMatchable($domain): bool
143143
{
144-
return null !== $domain
145-
&& strpos($domain, '.') > 0
144+
return strpos($domain, '.') > 0
146145
&& strlen($domain) === strcspn($domain, '][')
147146
&& !filter_var($domain, FILTER_VALIDATE_IP);
148147
}

tests/CacheTest.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
declare(strict_types=1);
44

5-
namespace pdp\tests;
5+
namespace Pdp\Tests;
66

77
use DateInterval;
8+
use Iterator;
89
use org\bovigo\vfs\vfsStream;
910
use Pdp\Cache;
1011
use PHPUnit\Framework\TestCase;
1112
use Psr\SimpleCache\InvalidArgumentException;
12-
use Traversable;
1313

1414
/**
1515
* Abstract PSR-16 tester.
@@ -47,8 +47,7 @@ public function tearDown()
4747
/**
4848
* @dataProvider storableValuesProvider
4949
*
50-
* @param mixed $expected
51-
* @param string $key
50+
* @param mixed $expected
5251
*/
5352
public function testSetGet($expected)
5453
{
@@ -387,7 +386,7 @@ public function testGetMultipleInvalidArg()
387386
// first value is requested.
388387
//
389388
// This extra line is just a precaution for that
390-
if ($result instanceof Traversable) {
389+
if ($result instanceof Iterator) {
391390
$result->current();
392391
}
393392
}

tests/CurlHttpClientTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace pdp\tests;
5+
namespace Pdp\Tests;
66

77
use Pdp\CurlHttpClient;
88
use Pdp\Exception;

tests/DomainTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace pdp\tests;
5+
namespace Pdp\Tests;
66

77
use Pdp\Domain;
88
use Pdp\Exception;

tests/ManagerTest.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace pdp\tests;
5+
namespace Pdp\Tests;
66

77
use org\bovigo\vfs\vfsStream;
88
use Pdp\Cache;
@@ -13,9 +13,6 @@
1313

1414
class ManagerTest extends TestCase
1515
{
16-
/**
17-
* @var Manager
18-
*/
1916
protected $manager;
2017
protected $cachePool;
2118
protected $cacheDir;

tests/PublicSuffixTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace pdp\tests;
5+
namespace Pdp\Tests;
66

77
use Pdp\Exception;
88
use Pdp\PublicSuffix;

tests/RulesTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace pdp\tests;
5+
namespace Pdp\Tests;
66

77
use Pdp\Cache;
88
use Pdp\CurlHttpClient;
@@ -257,8 +257,8 @@ public function testPublicSuffixSection()
257257
*
258258
* @see http://publicsuffix.org/list/
259259
*
260-
* @param string $input Domain and public suffix
261-
* @param string $expected Expected result
260+
* @param string|null $input Domain and public suffix
261+
* @param string|null $expected Expected result
262262
*/
263263
public function checkPublicSuffix($input, $expected)
264264
{

0 commit comments

Comments
 (0)