Skip to content

Commit 5ad49ef

Browse files
authored
Update coding standard (#24)
1 parent 0bc6db5 commit 5ad49ef

28 files changed

+95
-101
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343

4444
-
4545
name: "Run friendsofphp/php-cs-fixer"
46-
run: "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose"
46+
run: "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose --allow-risky=yes"
4747
phpstan:
4848
name: "PHPStan (${{ matrix.php-version }})"
4949

.php_cs.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22

33
$finder = PhpCsFixer\Finder::create()
44
->in('lib')
5+
->in('tests')
6+
->exclude([
7+
'Workspace',
8+
'Integration/Composer/project'
9+
])
510
;
611

712
return PhpCsFixer\Config::create()
813
->setRules([
914
'@PSR2' => true,
1015
'no_unused_imports' => true,
1116
'array_syntax' => ['syntax' => 'short'],
17+
'void_return' => true,
18+
'ordered_class_elements' => true,
19+
'single_quote' => true,
20+
'heredoc_indentation' => true,
21+
'global_namespace_import' => true,
1222
])
1323
->setFinder($finder)
1424
;

lib/Adapter/Composer/ComposerClassToFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private function getStrategies(): array
7575
];
7676
}
7777

78-
private function resolveFile(&$candidates, array $prefixes, NameInflector $inflector, ClassName $className)
78+
private function resolveFile(&$candidates, array $prefixes, NameInflector $inflector, ClassName $className): void
7979
{
8080
$fileCandidates = $this->getFileCandidates($className, $prefixes);
8181

lib/Adapter/Composer/ComposerFileToClass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Phpactor\ClassFileConverter\Domain\FileToClass;
88
use Phpactor\ClassFileConverter\Domain\ClassNameCandidates;
99
use Webmozart\PathUtil\Path;
10+
use InvalidArgumentException;
1011

1112
final class ComposerFileToClass implements FileToClass
1213
{
@@ -23,7 +24,7 @@ public function __construct(ClassLoader $classLoader)
2324
public function fileToClassCandidates(FilePath $filePath): ClassNameCandidates
2425
{
2526
if (false === $filePath->isAbsolute()) {
26-
throw new \InvalidArgumentException(sprintf(
27+
throw new InvalidArgumentException(sprintf(
2728
'Path must be absolute'
2829
));
2930
}

lib/Domain/ChainClassToFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function classToFileCandidates(ClassName $className): FilePathCandidates
2828
return FilePathCandidates::fromFilePaths($paths);
2929
}
3030

31-
private function add(ClassToFile $classToFile)
31+
private function add(ClassToFile $classToFile): void
3232
{
3333
$this->converters[] = $classToFile;
3434
}

lib/Domain/ChainFileToClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function fileToClassCandidates(FilePath $filePath): ClassNameCandidates
2828
return ClassNameCandidates::fromClassNames($classNames);
2929
}
3030

31-
private function add(FileToClass $fileToClass)
31+
private function add(FileToClass $fileToClass): void
3232
{
3333
$this->converters[] = $fileToClass;
3434
}

lib/Domain/ClassName.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ private function __construct()
1010
{
1111
}
1212

13+
public function __toString()
14+
{
15+
return $this->fullyQualifiedName;
16+
}
17+
1318
public static function fromString($string)
1419
{
1520
$new = new self();
@@ -18,11 +23,6 @@ public static function fromString($string)
1823
return $new;
1924
}
2025

21-
public function __toString()
22-
{
23-
return $this->fullyQualifiedName;
24-
}
25-
2626
public function namespace()
2727
{
2828
return substr($this->fullyQualifiedName, 0, (int) strrpos($this->fullyQualifiedName, '\\'));

lib/Domain/ClassNameCandidates.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
namespace Phpactor\ClassFileConverter\Domain;
44

5-
final class ClassNameCandidates implements \IteratorAggregate
5+
use IteratorAggregate;
6+
use ArrayIterator;
7+
use RuntimeException;
8+
9+
final class ClassNameCandidates implements IteratorAggregate
610
{
711
private $classNames = [];
812

@@ -20,7 +24,7 @@ public static function fromClassNames(array $classNames)
2024

2125
public function getIterator()
2226
{
23-
return new \ArrayIterator(array_values($this->classNames));
27+
return new ArrayIterator(array_values($this->classNames));
2428
}
2529

2630
public function noneFound(): bool
@@ -31,15 +35,15 @@ public function noneFound(): bool
3135
public function best(): ClassName
3236
{
3337
if (empty($this->classNames)) {
34-
throw new \RuntimeException(
38+
throw new RuntimeException(
3539
'There are no class name candidates'
3640
);
3741
}
3842

3943
return reset($this->classNames);
4044
}
4145

42-
private function add(ClassName $className)
46+
private function add(ClassName $className): void
4347
{
4448
$this->classNames[$className->__toString()] = $className;
4549
}

lib/Domain/FilePath.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ private function __construct(string $path)
1414
$this->path = $path;
1515
}
1616

17-
public function isAbsolute(): bool
17+
public function __toString()
1818
{
19-
return Path::isAbsolute($this->path);
19+
return $this->path;
2020
}
2121

22-
public function __toString()
22+
public function isAbsolute(): bool
2323
{
24-
return $this->path;
24+
return Path::isAbsolute($this->path);
2525
}
2626

2727
public static function fromString($path): FilePath

lib/Domain/FilePathCandidates.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
namespace Phpactor\ClassFileConverter\Domain;
44

5-
final class FilePathCandidates implements \IteratorAggregate
5+
use IteratorAggregate;
6+
use RuntimeException;
7+
use ArrayIterator;
8+
9+
final class FilePathCandidates implements IteratorAggregate
610
{
711
private $filePaths = [];
812

@@ -28,15 +32,15 @@ public function toArray(): array
2832
return $this->filePaths;
2933
}
3034

31-
public function add(FilePath $filePath)
35+
public function add(FilePath $filePath): void
3236
{
3337
$this->filePaths[] = $filePath;
3438
}
3539

3640
public function best(): FilePath
3741
{
3842
if (empty($this->filePaths)) {
39-
throw new \RuntimeException(
43+
throw new RuntimeException(
4044
'There are no file path candidates'
4145
);
4246
}
@@ -51,6 +55,6 @@ public function noneFound(): bool
5155

5256
public function getIterator()
5357
{
54-
return new \ArrayIterator($this->filePaths);
58+
return new ArrayIterator($this->filePaths);
5559
}
5660
}

0 commit comments

Comments
 (0)