Skip to content

Commit 6946ab8

Browse files
committed
Updated coding standard
1 parent 63e0ca6 commit 6946ab8

11 files changed

+69
-52
lines changed

build.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@
4141
passthru="true"
4242
checkreturn="true"
4343
>
44-
<arg value="--standard=ruleset.xml"/>
4544
<arg value="--extensions=php"/>
4645
<arg value="--encoding=utf-8"/>
4746
<arg value="--tab-width=4"/>
48-
<arg value="--ignore=tests/*/data"/>
4947
<arg value="-sp"/>
5048
<arg path="src"/>
5149
<arg path="tests"/>
@@ -59,11 +57,9 @@
5957
passthru="true"
6058
checkreturn="true"
6159
>
62-
<arg value="--standard=ruleset.xml"/>
6360
<arg value="--extensions=php"/>
6461
<arg value="--encoding=utf-8"/>
6562
<arg value="--tab-width=4"/>
66-
<arg value="--ignore=tests/*/data"/>
6763
<arg value="-sp"/>
6864
<arg path="src"/>
6965
<arg path="tests"/>

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
"nette/utils": "^2.3.0 || ^3.0.0"
1919
},
2020
"require-dev": {
21-
"consistence/coding-standard": "~0.13.0",
22-
"jakub-onderka/php-parallel-lint": "^0.9.2",
21+
"consistence/coding-standard": "^3.0.1",
22+
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
23+
"jakub-onderka/php-parallel-lint": "^1.0",
2324
"phing/phing": "^2.13.0",
2425
"phpstan/phpstan-php-parser": "^0.10",
2526
"phpstan/phpstan-phpunit": "^0.10",
2627
"phpstan/phpstan-strict-rules": "^0.10",
2728
"phpunit/phpunit": "^7.0",
2829
"satooshi/php-coveralls": "^1.0",
29-
"slevomat/coding-standard": "^2.0"
30+
"slevomat/coding-standard": "^4.5.2"
3031
},
3132
"autoload": {
3233
"psr-4": {

phpcs.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHPStan Nette">
3+
<rule ref="vendor/consistence/coding-standard/Consistence/ruleset.xml">
4+
<exclude name="Squiz.Functions.GlobalFunction.Found"/>
5+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>
6+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
7+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions"/>
8+
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
9+
</rule>
10+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
11+
<properties>
12+
<property name="caseSensitive" value="false"/>
13+
</properties>
14+
</rule>
15+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
16+
<properties>
17+
<property name="newlinesCountBetweenOpenTagAndDeclare" value="0"/>
18+
</properties>
19+
</rule>
20+
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
21+
<properties>
22+
<property name="usefulAnnotations" type="array" value="
23+
@dataProvider,
24+
@requires
25+
"/>
26+
</properties>
27+
</rule>
28+
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
29+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators"/>
30+
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
31+
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
32+
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
33+
<!-- <rule ref="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator"/>-->
34+
<!-- <rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/> -->
35+
<!-- <rule ref="SlevomatCodingStandard.PHP.ShortList"/> -->
36+
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
37+
<properties>
38+
<property name="rootNamespaces" type="array" value="src=>PHPStan,tests=>PHPStan"/>
39+
</properties>
40+
</rule>
41+
<exclude-pattern>tests/*/data</exclude-pattern>
42+
</ruleset>

ruleset.xml

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

src/Reflection/Nette/NetteObjectClassReflectionExtension.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
2828
return $getterMethod->isPublic();
2929
}
3030

31-
/**
32-
* @param \PHPStan\Reflection\ClassReflection $classReflection
33-
* @param string $propertyName
34-
* @return \PHPStan\Reflection\MethodReflection|null
35-
*/
36-
private function getMethodByProperty(ClassReflection $classReflection, string $propertyName)
31+
private function getMethodByProperty(ClassReflection $classReflection, string $propertyName): ?\PHPStan\Reflection\MethodReflection
3732
{
3833
$getterMethodName = sprintf('get%s', ucfirst($propertyName));
3934
if (!$classReflection->hasNativeMethod($getterMethodName)) {

tests/data/NetteObjectChild.php renamed to tests/NetteObjectChild.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php declare(strict_types = 1);
2-
namespace PHPStan\Tests;
2+
3+
namespace PHPStan;
34

45
class NetteObjectChild extends \Nette\Object
56
{

tests/Reflection/Nette/HtmlClassReflectionExtensionTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class HtmlClassReflectionExtensionTest extends \PHPStan\Testing\TestCase
1111
/** @var \PHPStan\Reflection\Nette\HtmlClassReflectionExtension */
1212
private $extension;
1313

14-
protected function setUp()
14+
protected function setUp(): void
1515
{
1616
$this->broker = $this->createBroker();
1717
$this->extension = new HtmlClassReflectionExtension();
@@ -39,13 +39,13 @@ public function dataHasMethod(): array
3939
* @param string $className
4040
* @param bool $result
4141
*/
42-
public function testHasMethod(string $className, bool $result)
42+
public function testHasMethod(string $className, bool $result): void
4343
{
4444
$classReflection = $this->broker->getClass($className);
4545
self::assertSame($result, $this->extension->hasMethod($classReflection, 'href'));
4646
}
4747

48-
public function testGetMethod()
48+
public function testGetMethod(): void
4949
{
5050
$classReflection = $this->broker->getClass(\Nette\Utils\Html::class);
5151
$methodReflection = $this->extension->getMethod($classReflection, 'href');
@@ -81,13 +81,13 @@ public function dataHasProperty(): array
8181
* @param string $className
8282
* @param bool $result
8383
*/
84-
public function testHasProperty(string $className, bool $result)
84+
public function testHasProperty(string $className, bool $result): void
8585
{
8686
$classReflection = $this->broker->getClass($className);
8787
self::assertSame($result, $this->extension->hasProperty($classReflection, 'href'));
8888
}
8989

90-
public function testGetProperty()
90+
public function testGetProperty(): void
9191
{
9292
$classReflection = $this->broker->getClass(\Nette\Utils\Html::class);
9393
$propertyReflection = $this->extension->getProperty($classReflection, 'href');

tests/Reflection/Nette/NetteObjectClassReflectionExtensionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class NetteObjectClassReflectionExtensionTest extends \PHPStan\Testing\TestCase
1111
/** @var \PHPStan\Reflection\Nette\NetteObjectClassReflectionExtension */
1212
private $extension;
1313

14-
protected function setUp()
14+
protected function setUp(): void
1515
{
1616
$this->broker = $this->createBroker();
1717
$this->extension = new NetteObjectClassReflectionExtension();
@@ -24,12 +24,12 @@ public function dataHasMethod(): array
2424
{
2525
$data = [];
2626
$data[] = [
27-
\PHPStan\Tests\SmartObjectChild::class,
27+
\PHPStan\SmartObjectChild::class,
2828
'onPublicEvent',
2929
true,
3030
];
3131
$data[] = [
32-
\PHPStan\Tests\SmartObjectChild::class,
32+
\PHPStan\SmartObjectChild::class,
3333
'onProtectedEvent',
3434
false,
3535
];
@@ -54,7 +54,7 @@ public function dataHasMethod(): array
5454
* @param string $method
5555
* @param bool $result
5656
*/
57-
public function testHasMethod(string $className, string $method, bool $result)
57+
public function testHasMethod(string $className, string $method, bool $result): void
5858
{
5959
$classReflection = $this->broker->getClass($className);
6060
self::assertSame($result, $this->extension->hasMethod($classReflection, $method));
@@ -67,7 +67,7 @@ public function dataHasProperty(): array
6767
{
6868
$data = [];
6969
$data[] = [
70-
\PHPStan\Tests\SmartObjectChild::class,
70+
\PHPStan\SmartObjectChild::class,
7171
'foo',
7272
false,
7373
];
@@ -97,7 +97,7 @@ public function dataHasProperty(): array
9797
* @param string $property
9898
* @param bool $result
9999
*/
100-
public function testHasProperty(string $className, string $property, bool $result)
100+
public function testHasProperty(string $className, string $property, bool $result): void
101101
{
102102
$classReflection = $this->broker->getClass($className);
103103
self::assertSame($result, $this->extension->hasProperty($classReflection, $property));

tests/Rule/Nette/DoNotExtendNetteObjectRuleTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ protected function getRule(): Rule
1212
return new DoNotExtendNetteObjectRule($this->createBroker());
1313
}
1414

15-
public function testSmartObjectChild()
15+
public function testSmartObjectChild(): void
1616
{
17-
$this->analyse([__DIR__ . '/../../data/SmartObjectChild.php'], []);
17+
$this->analyse([__DIR__ . '/../../SmartObjectChild.php'], []);
1818
}
1919

20-
public function testNetteObjectChild()
20+
public function testNetteObjectChild(): void
2121
{
2222
if (PHP_VERSION_ID >= 70200) {
2323
self::markTestSkipped('PHP 7.2 is incompatible with Nette\Object.');

tests/data/SmartObjectChild.php renamed to tests/SmartObjectChild.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php declare(strict_types = 1);
2-
namespace PHPStan\Tests;
2+
3+
namespace PHPStan;
34

45
class SmartObjectChild
56
{

0 commit comments

Comments
 (0)