Skip to content

Commit 35d68c7

Browse files
Merge pull request #26 from Phauthentic/new-rules
Adding Property related Rules
2 parents f3d2f3a + 7324231 commit 35d68c7

55 files changed

Lines changed: 4391 additions & 220 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ See individual rule documentation for detailed configuration examples. A [full c
2525
- [Class Must Be Readonly Rule](docs/rules/Class-Must-Be-Readonly-Rule.md)
2626
- [Class Must Have Specification Docblock Rule](docs/rules/Class-Must-Have-Specification-Docblock-Rule.md)
2727
- [Classname Must Match Pattern Rule](docs/rules/Classname-Must-Match-Pattern-Rule.md)
28-
- [Dependency Constraints Rule](docs/rules/Dependency-Constraints-Rule.md)
28+
- [Dependency Constraints Rule](docs/rules/Dependency-Constraints-Rule.md) *(deprecated, use Forbidden Dependencies Rule)*
29+
- [Forbidden Accessors Rule](docs/rules/Forbidden-Accessors-Rule.md)
30+
- [Forbidden Dependencies Rule](docs/rules/Forbidden-Dependencies-Rule.md)
2931
- [Forbidden Namespaces Rule](docs/rules/Forbidden-Namespaces-Rule.md)
32+
- [Forbidden Static Methods Rule](docs/rules/Forbidden-Static-Methods-Rule.md)
3033
- [Method Must Return Type Rule](docs/rules/Method-Must-Return-Type-Rule.md)
3134
- [Method Signature Must Match Rule](docs/rules/Method-Signature-Must-Match-Rule.md)
3235
- [Methods Returning Bool Must Follow Naming Convention Rule](docs/rules/Methods-Returning-Bool-Must-Follow-Naming-Convention-Rule.md)
3336
- [Modular Architecture Rule](docs/rules/Modular-Architecture-Rule.md)
37+
- [Property Must Match Rule](docs/rules/Property-Must-Match-Rule.md)
3438

3539
### Clean Code Rules
3640

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "library",
44
"require-dev": {
55
"phpstan/phpstan": "^2.1",
6-
"phpunit/phpunit": "^12.0",
6+
"phpunit/phpunit": "^12.5.8",
77
"squizlabs/php_codesniffer": "^3.12"
88
},
99
"autoload": {

composer.lock

Lines changed: 225 additions & 118 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\BoolNaming;
4+
5+
class EdgeCaseMethodBoolClass
6+
{
7+
public function __construct()
8+
{
9+
}
10+
11+
public function __toString(): string
12+
{
13+
return 'test';
14+
}
15+
16+
public function noReturnType()
17+
{
18+
return true;
19+
}
20+
21+
public function isValid(): bool
22+
{
23+
return true;
24+
}
25+
26+
public function check(): bool
27+
{
28+
return true;
29+
}
30+
}

data/Forbidden/ChildService.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Forbidden;
6+
7+
class ChildService extends ForbiddenService
8+
{
9+
public function callParent(): string
10+
{
11+
return parent::create();
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Forbidden;
6+
7+
class ForbiddenService
8+
{
9+
public static function create(): string
10+
{
11+
return 'created';
12+
}
13+
14+
public function callSelf(): string
15+
{
16+
return self::create();
17+
}
18+
19+
public function callStatic(): string
20+
{
21+
return static::create();
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace App\Domain;
4+
5+
$entity = new class {
6+
public function getName(): string
7+
{
8+
return 'name';
9+
}
10+
11+
public function setName(string $name): void
12+
{
13+
}
14+
};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace App\Domain;
4+
5+
class UserEntity
6+
{
7+
private string $name;
8+
private int $age;
9+
private bool $active;
10+
11+
public function getName(): string
12+
{
13+
return $this->name;
14+
}
15+
16+
public function setName(string $name): void
17+
{
18+
$this->name = $name;
19+
}
20+
21+
public function getAge(): int
22+
{
23+
return $this->age;
24+
}
25+
26+
public function setAge(int $age): void
27+
{
28+
$this->age = $age;
29+
}
30+
31+
protected function getActive(): bool
32+
{
33+
return $this->active;
34+
}
35+
36+
protected function setActive(bool $active): void
37+
{
38+
$this->active = $active;
39+
}
40+
41+
private function getPrivateValue(): string
42+
{
43+
return 'private';
44+
}
45+
46+
private function setPrivateValue(string $value): void
47+
{
48+
// This should not trigger an error (private)
49+
}
50+
51+
public function doSomething(): void
52+
{
53+
// Regular method, should not trigger
54+
}
55+
56+
public function get(): void
57+
{
58+
// Should not trigger - no uppercase letter after 'get'
59+
}
60+
61+
public function set(): void
62+
{
63+
// Should not trigger - no uppercase letter after 'set'
64+
}
65+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Service;
4+
5+
class ServiceWithAccessors
6+
{
7+
private string $config;
8+
9+
public function getConfig(): string
10+
{
11+
return $this->config;
12+
}
13+
14+
public function setConfig(string $config): void
15+
{
16+
$this->config = $config;
17+
}
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Service;
6+
7+
class DynamicCallService
8+
{
9+
public function dynamicMethod(): void
10+
{
11+
$method = 'calculate';
12+
\App\Utils\StaticHelper::$method();
13+
}
14+
15+
public function dynamicClass(): void
16+
{
17+
$class = \App\Utils\StaticHelper::class;
18+
$class::calculate();
19+
}
20+
}

0 commit comments

Comments
 (0)