Skip to content

Commit d072218

Browse files
committed
Apply new code standards to projects
1 parent 74a6715 commit d072218

File tree

13 files changed

+113
-49
lines changed

13 files changed

+113
-49
lines changed

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.PHONY: install-phive
2+
install-phive:
3+
mkdir tools; \
4+
wget -O tools/phive.phar https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar; \
5+
wget -O tools/phive.phar.asc https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar.asc; \
6+
gpg --keyserver pool.sks-keyservers.net --recv-keys 0x9D8A98B29B2D5D79; \
7+
gpg --verify tools/phive.phar.asc tools/phive.phar; \
8+
chmod +x tools/phive.phar
9+
10+
.PHONY: setup
11+
setup: install-phive
12+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phar-ga:latest php tools/phive.phar install --force-accept-unsigned
13+
14+
.PHONY: phpcs
15+
phpcs:
16+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpcs-ga:latest -s
17+
18+
.PHONY: phpcbf
19+
phpcbf:
20+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpcs-ga:latest phpcbf
21+
22+
.PHONY: phpstan
23+
phpstan:
24+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpstan-ga:latest analyse src --no-progress --configuration phpstan.neon
25+
26+
.PHONY: psalm
27+
psalm:
28+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.2 tools/psalm --show-info=true
29+
.PHONY: test
30+
test:
31+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.2 tools/phpunit
32+
33+
.PHONY: pre-commit-test
34+
pre-commit-test: test phpcs phpstan psalm
35+

phive.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3-
<phar name="phpunit" version="^6.5.5" installed="6.5.5" location="./tools/phpunit"/>
4-
<phar name="phpstan" version="^0.9.1" installed="0.9.1" location="./tools/phpstan"/>
3+
<phar name="phpunit" version="^8.4" installed="8.4.3" location="./tools/phpunit" copy="true"/>
4+
<phar name="psalm" version="^3.7.2" installed="3.11.2" location="./tools/psalm" copy="true"/>
55
</phive>

phpcs.xml.dist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="phpDocumentor">
3+
<description>The coding standard for phpDocumentor.</description>
4+
5+
<file>src</file>
6+
<file>tests/unit</file>
7+
<arg value="p"/>
8+
9+
<rule ref="phpDocumentor">
10+
</rule>
11+
</ruleset>

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
level: max

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

3-
<phpunit bootstrap="tests/common/bootstrap.php" colors="true">
3+
<phpunit bootstrap="vendor/autoload.php" colors="true">
44
<testsuites>
55
<testsuite name="unit">
66
<directory>./tests/unit/</directory>

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+
totallyTyped="true"
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 file:///composer/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/Element.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
/**
@@ -7,8 +8,6 @@
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*
10-
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
11-
* @license http://www.opensource.org/licenses/mit-license.php MIT
1211
* @link http://phpdoc.org
1312
*/
1413

@@ -22,10 +21,10 @@ interface Element
2221
/**
2322
* Returns the Fqsen of the element.
2423
*/
25-
public function getFqsen(): Fqsen;
24+
public function getFqsen() : Fqsen;
2625

2726
/**
2827
* Returns the name of the element.
2928
*/
30-
public function getName(): string;
29+
public function getName() : string;
3130
}

src/File.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
/**
@@ -7,8 +8,6 @@
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*
10-
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
11-
* @license http://www.opensource.org/licenses/mit-license.php MIT
1211
* @link http://phpdoc.org
1312
*/
1413

@@ -22,15 +21,15 @@ interface File
2221
/**
2322
* Returns the content of the file as a string.
2423
*/
25-
public function getContents(): string;
24+
public function getContents() : string;
2625

2726
/**
2827
* Returns md5 hash of the file.
2928
*/
30-
public function md5(): string;
29+
public function md5() : string;
3130

3231
/**
3332
* Returns an relative path to the file.
3433
*/
35-
public function path(): string;
34+
public function path() : string;
3635
}

src/Fqsen.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
/**
@@ -7,30 +8,33 @@
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*
10-
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
11-
* @license http://www.opensource.org/licenses/mit-license.php MIT
1211
* @link http://phpdoc.org
1312
*/
1413

1514
namespace phpDocumentor\Reflection;
1615

1716
use InvalidArgumentException;
17+
use function assert;
18+
use function end;
19+
use function explode;
20+
use function is_string;
21+
use function preg_match;
22+
use function sprintf;
23+
use function trim;
1824

1925
/**
2026
* Value Object for Fqsen.
2127
*
2228
* @link https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc-meta.md
29+
*
30+
* @psalm-immutable
2331
*/
2432
final class Fqsen
2533
{
26-
/**
27-
* @var string full quallified class name
28-
*/
34+
/** @var string full quallified class name */
2935
private $fqsen;
3036

31-
/**
32-
* @var string name of the element without path.
33-
*/
37+
/** @var string name of the element without path. */
3438
private $name;
3539

3640
/**
@@ -41,7 +45,9 @@ final class Fqsen
4145
public function __construct(string $fqsen)
4246
{
4347
$matches = [];
48+
4449
$result = preg_match(
50+
//phpcs:ignore Generic.Files.LineLength.TooLong
4551
'/^\\\\([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\\\]*)?(?:[:]{2}\\$?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*))?(?:\\(\\))?$/',
4652
$fqsen,
4753
$matches
@@ -59,22 +65,24 @@ public function __construct(string $fqsen)
5965
$this->name = $matches[2];
6066
} else {
6167
$matches = explode('\\', $fqsen);
62-
$this->name = trim(end($matches), '()');
68+
$name = end($matches);
69+
assert(is_string($name));
70+
$this->name = trim($name, '()');
6371
}
6472
}
6573

6674
/**
6775
* converts this class to string.
6876
*/
69-
public function __toString(): string
77+
public function __toString() : string
7078
{
7179
return $this->fqsen;
7280
}
7381

7482
/**
7583
* Returns the name of the element without path.
7684
*/
77-
public function getName(): string
85+
public function getName() : string
7886
{
7987
return $this->name;
8088
}

src/Location.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
/**
@@ -7,15 +8,15 @@
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*
10-
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
11-
* @license http://www.opensource.org/licenses/mit-license.php MIT
1211
* @link http://phpdoc.org
1312
*/
1413

1514
namespace phpDocumentor\Reflection;
1615

1716
/**
1817
* The location where an element occurs within a file.
18+
*
19+
* @psalm-immutable
1920
*/
2021
final class Location
2122
{
@@ -37,15 +38,15 @@ public function __construct(int $lineNumber, int $columnNumber = 0)
3738
/**
3839
* Returns the line number that is covered by this location.
3940
*/
40-
public function getLineNumber(): int
41+
public function getLineNumber() : int
4142
{
4243
return $this->lineNumber;
4344
}
4445

4546
/**
4647
* Returns the column number (character position on a line) for this location object.
4748
*/
48-
public function getColumnNumber(): int
49+
public function getColumnNumber() : int
4950
{
5051
return $this->columnNumber;
5152
}

src/Project.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
/**
@@ -7,8 +8,6 @@
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*
10-
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
11-
* @license http://www.opensource.org/licenses/mit-license.php MIT
1211
* @link http://phpdoc.org
1312
*/
1413

@@ -22,5 +21,5 @@ interface Project
2221
/**
2322
* Returns the name of the project.
2423
*/
25-
public function getName(): string;
24+
public function getName() : string;
2625
}

src/ProjectFactory.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
/**
@@ -7,8 +8,6 @@
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*
10-
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
11-
* @license http://www.opensource.org/licenses/mit-license.php MIT
1211
* @link http://phpdoc.org
1312
*/
1413

@@ -23,9 +22,7 @@ interface ProjectFactory
2322
/**
2423
* Creates a project from the set of files.
2524
*
26-
* @param string $name
2725
* @param File[] $files
28-
* @return Project
2926
*/
30-
public function create($name, array $files): Project;
27+
public function create(string $name, array $files) : Project;
3128
}

0 commit comments

Comments
 (0)