Skip to content

Commit

Permalink
refactor: Use friendsofphp/php-cs-fixer instead of squizlabs/php_code…
Browse files Browse the repository at this point in the history
…sniffer (#22)
  • Loading branch information
roadiz-ci committed Nov 6, 2024
1 parent 1161252 commit 36a8b7f
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 73 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,5 @@ jobs:
${{ runner.os }}-php-${{ matrix.php-version }}-
- name: Install Dependencies
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
- name: Run PHP Code Sniffer
run: vendor/bin/phpcs -p ./src
- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon
4 changes: 0 additions & 4 deletions Makefile

This file was deleted.

3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"symfony/http-foundation": "6.4.*"
},
"require-dev": {
"phpstan/phpstan": "^1.5.3",
"squizlabs/php_codesniffer": "^3.5"
"phpstan/phpstan": "^1.5.3"
},
"license": "MIT",
"authors": [
Expand Down
17 changes: 0 additions & 17 deletions phpcs.xml.dist

This file was deleted.

13 changes: 0 additions & 13 deletions src/DeclarationGeneratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ public function __construct(private readonly ParameterBag $nodeTypesBag)
{
}

/**
* @return ParameterBag
*/
public function getNodeTypesBag(): ParameterBag
{
return $this->nodeTypesBag;
Expand All @@ -34,11 +31,6 @@ public function getHumanBool(bool $bool): string
return $bool ? 'true' : 'false';
}

/**
* @param NodeTypeInterface $nodeType
*
* @return NodeTypeGenerator
*/
public function createForNodeType(NodeTypeInterface $nodeType): NodeTypeGenerator
{
return new NodeTypeGenerator(
Expand All @@ -47,11 +39,6 @@ public function createForNodeType(NodeTypeInterface $nodeType): NodeTypeGenerato
);
}

/**
* @param NodeTypeFieldInterface $field
*
* @return AbstractFieldGenerator
*/
public function createForNodeTypeField(NodeTypeFieldInterface $field): AbstractFieldGenerator
{
return match (true) {
Expand Down
25 changes: 9 additions & 16 deletions src/Generators/AbstractFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ abstract class AbstractFieldGenerator
protected NodeTypeFieldInterface $field;
protected ParameterBag $nodeTypesBag;

/**
* @param NodeTypeFieldInterface $field
* @param ParameterBag $nodeTypesBag
*/
public function __construct(
NodeTypeFieldInterface $field,
ParameterBag $nodeTypesBag
ParameterBag $nodeTypesBag,
) {
$this->field = $field;
$this->nodeTypesBag = $nodeTypesBag;
Expand All @@ -36,18 +32,18 @@ abstract protected function getType(): string;

private function getDeclaration(): string
{
return static::INDENTATION_MARK .
$this->field->getVarName() .
$this->getNullableAssertion() . ': ' .
return static::INDENTATION_MARK.
$this->field->getVarName().
$this->getNullableAssertion().': '.
$this->getType();
}

public function getContents(): string
{
return implode(PHP_EOL, [
$this->getIntroduction(),
$this->getDeclaration()
]);
$this->getIntroduction(),
$this->getDeclaration(),
]);
}

protected function getIntroductionLines(): array
Expand All @@ -60,19 +56,16 @@ protected function getIntroductionLines(): array
}

if (!empty($this->field->getGroupName())) {
$lines[] = 'Group: ' . $this->field->getGroupName();
$lines[] = 'Group: '.$this->field->getGroupName();
}

return $lines;
}

/**
* @return string
*/
public function getIntroduction(): string
{
return implode(PHP_EOL, array_map(function (string $line) {
return static::INDENTATION_MARK . '// ' . $line;
return static::INDENTATION_MARK.'// '.$line;
}, $this->getIntroductionLines()));
}
}
6 changes: 4 additions & 2 deletions src/Generators/ChildrenNodeFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ public function getContents(): string
$this->getIntroduction(),
]);
}

protected function getIntroductionLines(): array
{
$lines = [
'This node-type uses "blocks" which are available through parent RoadizNodesSources.blocks'
'This node-type uses "blocks" which are available through parent RoadizNodesSources.blocks',
];
if (!empty($this->field->getDefaultValues())) {
$lines[] = 'Possible block node-types: ' . $this->field->getDefaultValues();
$lines[] = 'Possible block node-types: '.$this->field->getDefaultValues();
}

return $lines;
}

Expand Down
5 changes: 2 additions & 3 deletions src/Generators/DeclarationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ final class DeclarationGenerator
private array $nodeTypes;

/**
* @param DeclarationGeneratorFactory $generatorFactory
* @param NodeTypeInterface[] $nodeTypes
*/
public function __construct(
private readonly DeclarationGeneratorFactory $generatorFactory,
array $nodeTypes = []
array $nodeTypes = [],
) {
if (empty($nodeTypes)) {
$this->nodeTypes = array_unique($this->generatorFactory->getNodeTypesBag()->all());
Expand All @@ -41,7 +40,7 @@ public function getContents(): string

$blocks[] = $this->getAllTypesInterface();

return implode(PHP_EOL . PHP_EOL, $blocks);
return implode(PHP_EOL.PHP_EOL, $blocks);
}

private function getAllTypesInterface(): string
Expand Down
9 changes: 6 additions & 3 deletions src/Generators/EnumFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ protected function getType(): string
);
if (count($defaultValues) > 0) {
$defaultValues = array_map(function (string $value) {
return '\'' . $value . '\'';
return '\''.$value.'\'';
}, $defaultValues);
return implode(' | ', $defaultValues) . ' | null';

return implode(' | ', $defaultValues).' | null';
}
}

return 'string';
case $this->field->isMultiple():
return 'Array<string>';
Expand All @@ -36,8 +38,9 @@ protected function getIntroductionLines(): array
{
$lines = parent::getIntroductionLines();
if (!empty($this->field->getDefaultValues())) {
$lines[] = 'Possible values: ' . $this->field->getDefaultValues();
$lines[] = 'Possible values: '.$this->field->getDefaultValues();
}

return $lines;
}
}
7 changes: 5 additions & 2 deletions src/Generators/NodeReferencesFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function getNullableAssertion(): string

protected function getType(): string
{
return 'Array<' . $this->getUnionType() . '>';
return 'Array<'.$this->getUnionType().'>';
}

/**
Expand All @@ -27,8 +27,10 @@ private function getLinkedNodeTypes(): array
return [];
}
$nodeTypeNames = explode(',', $this->field->getDefaultValues());

return array_values(array_filter(array_map(function (string $name) {
$nodeType = $this->nodeTypesBag->get(trim($name));

return $nodeType instanceof NodeTypeInterface ? $nodeType : null;
}, $nodeTypeNames)));
}
Expand All @@ -50,8 +52,9 @@ protected function getIntroductionLines(): array
{
$lines = parent::getIntroductionLines();
if (!empty($this->field->getDefaultValues())) {
$lines[] = 'Possible values: ' . $this->field->getDefaultValues();
$lines[] = 'Possible values: '.$this->field->getDefaultValues();
}

return $lines;
}
}
18 changes: 9 additions & 9 deletions src/Generators/NodeTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class NodeTypeGenerator

public function __construct(
private readonly NodeTypeInterface $nodeType,
private readonly DeclarationGeneratorFactory $generatorFactory
private readonly DeclarationGeneratorFactory $generatorFactory,
) {
$this->fieldGenerators = [];

Expand Down Expand Up @@ -47,16 +47,16 @@ public function getContents(): string
*/
return implode(PHP_EOL, [
$this->getIntroduction(),
$this->getInterfaceBody()
$this->getInterfaceBody(),
]);
}

protected function getInterfaceBody(): string
{
$lines = [
'export interface ' . $this->nodeType->getSourceEntityClassName() . ' extends RoadizNodesSources {',
'export interface '.$this->nodeType->getSourceEntityClassName().' extends RoadizNodesSources {',
$this->getFieldsContents(),
'}'
'}',
];

return implode(PHP_EOL, $lines);
Expand All @@ -67,18 +67,18 @@ protected function getIntroduction(): string
$lines = [
'',
$this->nodeType->getLabel(),
''
'',
];
if (!empty($this->nodeType->getDescription())) {
$lines[] = $this->nodeType->getDescription();
}

$lines[] = 'Reachable: ' . $this->generatorFactory->getHumanBool($this->nodeType->isReachable());
$lines[] = 'Publishable: ' . $this->generatorFactory->getHumanBool($this->nodeType->isPublishable());
$lines[] = 'Visible: ' . $this->generatorFactory->getHumanBool($this->nodeType->isVisible());
$lines[] = 'Reachable: '.$this->generatorFactory->getHumanBool($this->nodeType->isReachable());
$lines[] = 'Publishable: '.$this->generatorFactory->getHumanBool($this->nodeType->isPublishable());
$lines[] = 'Visible: '.$this->generatorFactory->getHumanBool($this->nodeType->isVisible());

return implode(PHP_EOL, array_map(function (string $line) {
return '// ' . $line;
return '// '.$line;
}, $lines));
}

Expand Down

0 comments on commit 36a8b7f

Please sign in to comment.