Skip to content

Commit

Permalink
Update csfixer rules to v.3
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusValeraDev committed Jul 4, 2021
1 parent cac7840 commit 38297b4
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 115 deletions.
60 changes: 60 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Finder;
use PhpCsFixer\Config;

$finder = Finder::create()
->files()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests');

return (new Config())
->setFinder($finder)
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'braces' => [
'allow_single_line_closure' => true,
'allow_single_line_anonymous_class_with_empty_body' => true,
],
'concat_space' => ['spacing' => 'one'],
'declare_strict_types' => true,
'function_typehint_space' => true,
'list_syntax' => ['syntax' => 'short'],
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_leading_namespace_whitespace' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_whitespace_before_comma_in_array' => true,
'no_unused_imports' => true,
'normalize_index_brace' => true,
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],
'php_unit_method_casing' => ['case' => 'snake_case'],
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_annotation_without_dot' => true,
'phpdoc_indent' => true,
'phpdoc_line_span' => ['const' => 'single', 'property' => 'single', 'method' => 'multi'],
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_summary' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_annotation_correct_order' => true,
'phpdoc_var_without_name' => true,
'single_quote' => true,
'trailing_comma_in_multiline' => [
'elements' => ['arrays'],
],
'trim_array_spaces' => true,
'void_return' => true,
]);
45 changes: 0 additions & 45 deletions .php_cs.dist

This file was deleted.

12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/CodeGenerator/Domain/CommandArgumentsParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function parse(string $desiredNamespace): CommandArguments

foreach ($allPsr4Combinations as $psr4Combination) {
$psr4Key = $psr4Combination . '\\';

if (isset($psr4[$psr4Key])) {
return $this->foundPsr4($psr4Key, $psr4[$psr4Key], $desiredNamespace);
}
Expand Down Expand Up @@ -80,8 +81,8 @@ private function allPossiblePsr4Combinations(string $desiredNamespace): array

private function foundPsr4(string $psr4Key, string $psr4Value, string $desiredNamespace): CommandArguments
{
$rootDir = substr($psr4Value, 0, -1);
$rootNamespace = substr($psr4Key, 0, -1);
$rootDir = mb_substr($psr4Value, 0, -1);
$rootNamespace = mb_substr($psr4Key, 0, -1);
$targetDirectory = str_replace(['/', $rootNamespace, '\\'], ['\\', $rootDir, '/'], $desiredNamespace);
$namespace = str_replace([$rootDir, '/'], [$rootNamespace, '\\'], $targetDirectory);

Expand Down
1 change: 1 addition & 0 deletions src/CodeGenerator/Domain/FilenameSanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static function expectedFilenames(string $glue = ', '): string
public function sanitize(string $filename): string
{
$percents = [];

foreach (self::EXPECTED_FILENAMES as $expected) {
$percents[$expected] = similar_text($expected, $filename, $percent);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/AbstractConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class AbstractConfig
use ConfigResolverAwareTrait;

/**
* @param mixed $default
* @param null|mixed $default
*
* @throws ConfigException
*
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/AbstractFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class AbstractFacade

protected function getFactory(): AbstractFactory
{
if ($this->factory === null) {
if (null === $this->factory) {
$this->factory = $this->resolveFactory();
}

Expand Down
32 changes: 15 additions & 17 deletions src/Framework/ClassResolver/AbstractClassResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@

abstract class AbstractClassResolver
{
/** @var array<string,object|mixed> */
/** @var array<string,mixed|object> */
protected static array $cachedInstances = [];

protected static ?ClassResolverFactory $classResolverFactory = null;
protected static ?ClassNameFinderInterface $classNameFinder = null;

protected ?ClassInfo $classInfo = null;

abstract public function resolve(object $callerClass): ?object;

abstract protected function getResolvableType(): string;

/**
* @return mixed|null
* @return null|mixed
*/
public function doResolve(object $callerClass)
{
Expand All @@ -34,7 +30,7 @@ public function doResolve(object $callerClass)

$resolvedClassName = $this->findClassName();

if ($resolvedClassName === null) {
if (null === $resolvedClassName) {
return null;
}

Expand All @@ -48,6 +44,15 @@ public function setCallerObject(object $callerClass): void
$this->classInfo = new ClassInfo($callerClass);
}

public function getClassInfo(): ClassInfo
{
assert($this->classInfo instanceof ClassInfo);

return $this->classInfo;
}

abstract protected function getResolvableType(): string;

private function getCacheKey(): string
{
assert($this->classInfo instanceof ClassInfo);
Expand All @@ -65,7 +70,7 @@ private function findClassName(): ?string

private function getClassNameFinder(): ClassNameFinderInterface
{
if (static::$classNameFinder === null) {
if (null === static::$classNameFinder) {
static::$classNameFinder = $this->getClassResolverFactory()->createClassNameFinder();
}

Expand All @@ -74,22 +79,15 @@ private function getClassNameFinder(): ClassNameFinderInterface

private function getClassResolverFactory(): ClassResolverFactory
{
if (static::$classResolverFactory === null) {
if (null === static::$classResolverFactory) {
static::$classResolverFactory = new ClassResolverFactory();
}

return static::$classResolverFactory;
}

public function getClassInfo(): ClassInfo
{
assert($this->classInfo instanceof ClassInfo);

return $this->classInfo;
}

/**
* @return object|null
* @return null|object
*/
private function createInstance(string $resolvedClassName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/ClassResolver/Config/ConfigResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function resolve(object $callerClass): AbstractConfig
/** @var ?AbstractConfig $resolved */
$resolved = $this->doResolve($callerClass);

if ($resolved === null) {
if (null === $resolved) {
throw new ConfigNotFoundException($this->getClassInfo());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function resolve(object $callerClass): AbstractDependencyProvider
/** @var ?AbstractDependencyProvider $resolved */
$resolved = $this->doResolve($callerClass);

if ($resolved === null) {
if (null === $resolved) {
throw new DependencyProviderNotFoundException($this->getClassInfo());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Framework/ClassResolver/Factory/FactoryResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function resolve(object $callerClass): AbstractFactory
/** @var ?AbstractFactory $resolved */
$resolved = $this->doResolve($callerClass);

if ($resolved === null) {
if (null === $resolved) {
throw new FactoryNotFoundException($this->getClassInfo());
}

Expand Down
Loading

0 comments on commit 38297b4

Please sign in to comment.