Skip to content

Commit

Permalink
Merge pull request #10 from sitegeist/9-symfony-7-and-php-83-support
Browse files Browse the repository at this point in the history
9 symfony 7 and php 83 support
  • Loading branch information
ulrichmathes authored Oct 11, 2024
2 parents 5f8517c + 2e56d97 commit 4959291
Show file tree
Hide file tree
Showing 24 changed files with 197 additions and 157 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

-
name: Install composer dependencies
run: composer install --prefer-dist --no-progress --no-suggest
run: composer install --prefer-dist --no-progress

-
name: PHP Linting
Expand All @@ -45,7 +45,7 @@ jobs:
strategy:
max-parallel: 2
matrix:
php-version: [8.0, 8.1, 8.2]
php-version: [8.3, 8.2]

name: Unit (PHP ${{ matrix.php-version }})
steps:
Expand All @@ -71,7 +71,7 @@ jobs:

-
name: Install composer dependencies
run: composer install --prefer-dist --no-progress --no-suggest
run: composer install --prefer-dist --no-progress

-
name: PHP Unit Testing
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
"issues": "https://github.com/sitegeist/fluid-components-linter/issues"
},
"require": {
"php": ">=8.0.0",
"symfony/config": "^5.0 || ^6.0",
"symfony/console": "^5.0 || ^6.0",
"typo3fluid/fluid": "^2.6"
"php": ">=8.2.0",
"symfony/config": "^5.0 || ^6.0 || ^7.0",
"symfony/console": "^5.0 || ^6.0 || ^7.0",
"typo3fluid/fluid": "^4.0 || ^2.6"
},
"require-dev": {
"editorconfig-checker/editorconfig-checker": "^10.0",
"squizlabs/php_codesniffer": "^3.0",
"phpunit/phpunit": "^9.2",
"phpunit/phpunit": "^11.2",
"symfony/var-dumper": "^5.1",
"phpstan/phpstan": "^0.12.38"
"phpstan/phpstan": "^1.11"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 1 addition & 3 deletions src/Classes/CodeQuality/Check/ComponentVariablesCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ protected function extractUsedVariables(): array
$this->component->rootNode,
ObjectAccessorNode::class
);
return array_map(function (ObjectAccessorNode $node) {
return $node->getObjectPath();
}, $usedVariables);
return array_map(fn(ObjectAccessorNode $node) => $node->getObjectPath(), $usedVariables);
}
}
4 changes: 1 addition & 3 deletions src/Classes/CodeQuality/Check/DocumentationFixtureCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public function check(): array
return $issues;
}

$fixtureFiles = array_map(function ($fixtureFile) use ($directory, $name) {
return sprintf($fixtureFile, $directory, $name);
}, $this->fixtureFiles);
$fixtureFiles = array_map(fn($fixtureFile) => sprintf($fixtureFile, $directory, $name), $this->fixtureFiles);
$fixtureFile = array_filter($fixtureFiles, 'file_exists');
$fixtureFile = reset($fixtureFile);

Expand Down
2 changes: 1 addition & 1 deletion src/Classes/CodeQuality/Check/ParamTypeNamespaceCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function check(): array
$issues = [];
foreach ($this->component->paramNodes as $paramNode) {
$arguments = $paramNode->getArguments();
if (substr((string) $arguments['type'], 0, 1) === '\\') {
if (str_starts_with((string) $arguments['type'], '\\')) {
$issues[] = $this->issue('Type is specified with leading backslash for parameter %s: %s', [
$arguments['name'],
$arguments['type']
Expand Down
8 changes: 3 additions & 5 deletions src/Classes/CodeQuality/Check/ViewHelpersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function check(): array
foreach ($this->configuration['renderer']['viewHelperRestrictions'] as $restriction) {
$pattern = $this->createViewHelperPattern($restriction['viewHelperName']);
foreach ($usedViewHelpers as $tagName) {
if (preg_match($pattern, $tagName)) {
if (preg_match($pattern, (string) $tagName)) {
$issues[] = $this->issue($restriction['message'], [
$tagName
])->setSeverity($restriction['severity']);
Expand All @@ -30,7 +30,7 @@ public function check(): array
protected function createViewHelperPattern(string $viewHelperName): string
{
$pattern = preg_quote($viewHelperName, '#');
if (substr($viewHelperName, -1, 1) !== '.') {
if (!str_ends_with($viewHelperName, '.')) {
$pattern .= '$';
}
return '#^' . $pattern . '#';
Expand All @@ -42,9 +42,7 @@ protected function extractUsedViewHelpers(): array
$this->component->rootNode,
ViewHelperNode::class
);
$introspectedViewHelpers = array_filter($usedViewHelpers, function (ViewHelperNode $node) {
return $node->getUninitializedViewHelper() instanceof IntrospectionViewHelper;
});
$introspectedViewHelpers = array_filter($usedViewHelpers, fn(ViewHelperNode $node) => $node->getUninitializedViewHelper() instanceof IntrospectionViewHelper);
return array_map(function (ViewHelperNode $node) {
/** @var IntrospectionViewHelper */
$introspectionViewHelper = $node->getUninitializedViewHelper();
Expand Down
27 changes: 12 additions & 15 deletions src/Classes/CodeQuality/Issue/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@

class Issue implements IssueInterface
{
protected $checkName = '';
protected $description;
protected $data;

protected $categories = [];
protected $severity = IssueInterface::SEVERITY_MAJOR;

protected $file = '';
protected $line = null;
protected $column = null;

public function __construct(string $description, array $data, string $file, int $line = null, int $column = null)
{
$this->description = $description;
$this->data = $data;
protected string $checkName = '';

protected array $categories = [];
protected string $severity = IssueInterface::SEVERITY_MAJOR;

public function __construct(
protected string $description,
protected array $data,
protected string $file,
protected ?int $line = null,
protected ?int $column = null,
) {
$this->setLocation($file, $line, $column);
}

Expand Down
12 changes: 6 additions & 6 deletions src/Classes/CodeQuality/Issue/IssueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

interface IssueInterface
{
const SEVERITY_INFO = 'info';
const SEVERITY_MINOR = 'minor';
const SEVERITY_MAJOR = 'major';
const SEVERITY_CRITICAL = 'critical';
const SEVERITY_BLOCKER = 'blocker';
public const SEVERITY_INFO = 'info';
public const SEVERITY_MINOR = 'minor';
public const SEVERITY_MAJOR = 'major';
public const SEVERITY_CRITICAL = 'critical';
public const SEVERITY_BLOCKER = 'blocker';

/**
* Ordered list of severities based on their... severity
*/
const SEVERITIES = [
public const SEVERITIES = [
self::SEVERITY_INFO,
self::SEVERITY_MINOR,
self::SEVERITY_MAJOR,
Expand Down
21 changes: 7 additions & 14 deletions src/Classes/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
use Sitegeist\FluidComponentsLinter\CodeQuality\Issue\IssueInterface;
use Sitegeist\FluidComponentsLinter\CodeQuality\Output\GroupedOutput;
use Sitegeist\FluidComponentsLinter\CodeQuality\Output\JsonOutput;
use Sitegeist\FluidComponentsLinter\Configuration\LintConfiguration;
use Sitegeist\FluidComponentsLinter\Exception\ConfigurationException;
use Sitegeist\FluidComponentsLinter\Service\CodeQualityService;
use Sitegeist\FluidComponentsLinter\Service\ComponentService;
use Sitegeist\FluidComponentsLinter\Service\ConfigurationService;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -20,22 +18,19 @@

class LintCommand extends Command
{
protected static $defaultName = 'lint';

/**
* Define severities which will lead to an exit status 0
*
* @var array
*/
protected $fatalSeverities = [
protected array $fatalSeverities = [
IssueInterface::SEVERITY_BLOCKER,
IssueInterface::SEVERITY_CRITICAL,
IssueInterface::SEVERITY_MAJOR
];

protected function configure()
protected function configure(): void
{
$this
->setName('lint')
->setDescription('Validates fluid components based on a specified ruleset')
->addArgument(
'paths',
Expand Down Expand Up @@ -85,7 +80,7 @@ protected function configure()
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$configurationService = new ConfigurationService;
Expand Down Expand Up @@ -121,9 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$skipSeverities = $this->determineSeveritiesToSkip($input->getOption('severity'));
if (!empty($skipSeverities)) {
$issues = array_filter($issues, function (IssueInterface $issue) use ($skipSeverities) {
return !in_array($issue->getSeverity(), $skipSeverities);
});
$issues = array_filter($issues, fn(IssueInterface $issue) => !in_array($issue->getSeverity(), $skipSeverities));
}

if ($input->getOption('json')) {
Expand Down Expand Up @@ -154,7 +147,7 @@ protected function determineExitStatus(array $issues): int
return 0;
}

protected function determineSeveritiesToSkip(string $minSeverity)
protected function determineSeveritiesToSkip(string $minSeverity): array
{
$skipSeverities = [];
foreach (IssueInterface::SEVERITIES as $severity) {
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/Configuration/LintConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class LintConfiguration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('fclint');
/** @var TreeNode */
Expand Down
7 changes: 4 additions & 3 deletions src/Classes/Fluid/ViewHelper/ViewHelperResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

namespace Sitegeist\FluidComponentsLinter\Fluid\ViewHelper;

use TYPO3Fluid\Fluid\Core\Parser\Exception as ParserException;
use Sitegeist\FluidComponentsLinter\ViewHelpers\IntrospectionViewHelper;
use TYPO3Fluid\Fluid\Core\Parser\Exception as ParserException;
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface;

class ViewHelperResolver extends \TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperResolver
{
public function createViewHelperInstanceFromClassName($viewHelperClassName)
public function createViewHelperInstanceFromClassName($viewHelperClassName): ViewHelperInterface
{
$parts = explode('\\', $viewHelperClassName);
$methodIdentifier = array_pop($parts);
Expand All @@ -25,7 +26,7 @@ public function resolveViewHelperClassName($namespaceIdentifier, $methodIdentifi
{
try {
return parent::resolveViewHelperClassName($namespaceIdentifier, $methodIdentifier);
} catch (ParserException $e) {
} catch (ParserException) {
// Redirect missing ViewHelpers to introspection placeholder
return sprintf(
'%s\\%s\\%s',
Expand Down
19 changes: 7 additions & 12 deletions src/Classes/Service/CodeQualityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@
use Sitegeist\FluidComponentsLinter\CodeQuality\Issue\IssueInterface;
use Sitegeist\FluidComponentsLinter\Exception\ComponentStructureException;
use Sitegeist\FluidComponentsLinter\Fluid\ViewHelper\ViewHelperResolver;
use TYPO3Fluid\Fluid\Core\Parser\Exception;
use TYPO3Fluid\Fluid\View\TemplateView;

class CodeQualityService
{
/** @var array */
protected $configuration;
protected ?TemplateView $view = null;

/** @var string[] */
protected $checks;

/** @var TemplateView */
protected $view;

public function __construct(array $configuration, array $checks)
{
$this->configuration = $configuration;
public function __construct(
protected array $configuration,
protected array $checks, // @var string[]
) {
$this->initializeChecks($checks);
$this->initializeView();
}
Expand Down Expand Up @@ -60,7 +55,7 @@ public function validateComponent(string $path): array
file_get_contents($path),
$path
);
} catch (\TYPO3Fluid\Fluid\Core\Parser\Exception $e) {
} catch (Exception $e) {
preg_match('#in template .+, line ([0-9]+) at character ([0-9]+).#', $e->getMessage(), $matches);
$issue = $this->blocker($e->getMessage(), $path, (int) $matches[1], (int) $matches[2]);
return [$issue];
Expand Down
22 changes: 5 additions & 17 deletions src/Classes/Service/ComponentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class ComponentService
/**
* Collection of paths that have already been scanned for components;
* this prevents infinite loops caused by circular symlinks
*
* @var array
*/
protected $scannedPaths;
protected array $scannedPaths = [];

/**
* Finds all components in the specified paths
Expand All @@ -22,10 +20,10 @@ class ComponentService
*/
public function findComponentsInPaths(array $paths, string $ext): array
{
$components = $this->scannedPaths = [];
$components = [];
foreach ($paths as $path) {
if (!is_dir($path)) {
if (file_exists($path) && substr($path, - strlen($ext)) == $ext) {
if (file_exists($path) && str_ends_with((string) $path, $ext)) {
$components[] = $path;
}
continue;
Expand All @@ -42,36 +40,26 @@ public function findComponentsInPaths(array $paths, string $ext): array
/**
* Removes all items from the provided array of component paths
* that match the provided ignore list
*
* @param array $components
* @param array $ignoreList
* @return array
*/
public function removeComponentsFromIgnoreList(array $components, array $ignoreList): array
{
if (empty($ignoreList)) {
return $components;
}

$ignorePattern = $this->buildPattern($ignoreList);
$ignorePattern = static::buildPattern($ignoreList);
if (!$ignorePattern) {
throw new \Exception(sprintf(
'Invalid ignore pattern provided: %s',
print_r($ignoreList, true)
), 1601484307);
}

return array_filter($components, function ($path) use ($ignorePattern) {
return !preg_match($ignorePattern, $path);
});
return array_filter($components, fn($path) => !preg_match($ignorePattern, (string) $path));
}

/**
* Searches recursively for component files in a directory
*
* @param string $path
* @param string $ext
* @return array
*/
protected function scanForComponents(string $path, string $ext): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Classes/Service/FluidService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public function generateNodeExceptionPreview(NodeInterface $node): string
if ($uninitializedViewHelper instanceof IntrospectionViewHelper) {
return $uninitializedViewHelper->getViewhelperTag();
} else {
return get_class($uninitializedViewHelper);
return $uninitializedViewHelper::class;
}
} elseif ($node instanceof TextNode) {
return trim($node->getText());
} elseif ($node instanceof ObjectAccessorNode) {
return '{' . $node->getObjectPath() . '}';
} else {
return get_class($node);
return $node::class;
}
}

Expand Down
Loading

0 comments on commit 4959291

Please sign in to comment.