Skip to content

Commit

Permalink
Increase psalm / phpstan level
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Oct 7, 2021
1 parent 9929d6a commit 1aa5c38
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 15 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.84",
"phpstan/phpstan-phpunit": "^0.12.16",
"phpstan/phpstan-strict-rules": "^0.12.10",
"phpstan/phpstan-symfony": "^0.12.44",
"psalm/plugin-phpunit": "^0.15",
"symfony/console": "^4.4 || ^5.3",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon

parameters:
level: 6
level: 8
bootstrapFiles:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
paths:
Expand Down
8 changes: 8 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.10.0@916b098b008f6de4543892b1e0651c1c3b92cbfa">
<file src="src/DependencyInjection/Configuration.php">
<PossiblyUndefinedMethod occurrences="1">
<code>children</code>
</PossiblyUndefinedMethod>
</file>
</files>
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="4" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" autoloader="vendor/bin/.phpunit/phpunit/vendor/autoload.php">
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="3" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" autoloader="vendor/bin/.phpunit/phpunit/vendor/autoload.php" errorBaseline="psalm-baseline.xml">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
Expand Down
16 changes: 14 additions & 2 deletions src/Command/SitemapGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,24 @@ private function moveTemporaryFile(string $tempDir, string $permanentDir): void
{
$oldFiles = Finder::create()->files()->name('sitemap*.xml')->in($permanentDir);
foreach ($oldFiles as $file) {
$this->filesystem->remove($file->getRealPath());
$pathname = $file->getRealPath();

if (false === $pathname) {
throw new \LogicException(sprintf('File %s does not exist', $file));
}

$this->filesystem->remove($pathname);
}

$newFiles = Finder::create()->files()->name('sitemap*.xml')->in($tempDir);
foreach ($newFiles as $file) {
$this->filesystem->rename($file->getRealPath(), sprintf('%s/%s', $permanentDir, $file->getFilename()));
$pathname = $file->getRealPath();

if (false === $pathname) {
throw new \LogicException(sprintf('File %s does not exist', $file));
}

$this->filesystem->rename($pathname, sprintf('%s/%s', $permanentDir, $file->getFilename()));
}
}
}
1 change: 1 addition & 0 deletions src/DependencyInjection/Compiler/ServiceCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class ServiceCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
/** @var array<string, mixed> $config */
$config = $container->getParameter('sonata.seo.config');

$definition = $container->findDefinition($config['default']);
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/SonataSeoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function load(array $configs, ContainerBuilder $container): void
$config = $this->processConfiguration($configuration, $configs);
$config = $this->fixConfiguration($config);

/** @var array<string, mixed> $bundles */
$bundles = $container->getParameter('kernel.bundles');

$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
Expand Down
4 changes: 3 additions & 1 deletion src/Sitemap/SourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public function __construct()
*/
public function addSource(string $group, SourceIteratorInterface $source, array $types = []): void
{
if (!isset($this->sources[$group])) {
if (!isset($this->sources[$group]) || null === $this->sources[$group]) {
$this->sources[$group] = new Source();
}

\assert(null !== $this->sources[$group]);

$this->sources[$group]->addSource($source);

if ([] !== $types) {
Expand Down
6 changes: 3 additions & 3 deletions src/Twig/Extension/SeoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public function getMetadatas(): string
{
$html = '';
foreach ($this->page->getMetas() as $type => $metas) {
foreach ((array) $metas as $name => $meta) {
foreach ($metas as $name => $meta) {
[$content, $extras] = $meta;

if (!empty($content)) {
if ('' !== $content) {
$html .= sprintf(
"<meta %s=\"%s\" content=\"%s\" />\n",
$type,
Expand Down Expand Up @@ -112,7 +112,7 @@ public function getHeadAttributes(): string

public function getLinkCanonical(): string
{
if ($this->page->getLinkCanonical()) {
if ('' !== $this->page->getLinkCanonical()) {
return sprintf("<link rel=\"canonical\" href=\"%s\"/>\n", $this->page->getLinkCanonical());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function testGlobalTitle(): void

$page = $container->get('sonata.seo.custom.page');

\assert($page instanceof SeoPageInterface);

static::assertSame('Project name', $page->getOriginalTitle());
static::assertSame('Prefix Project name Suffix', $page->getTitle());
}
Expand Down
1 change: 1 addition & 0 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function testKeysAreNotNormalized(): void
public function testWithYamlConfig(): void
{
$values = Yaml::parse(
/* @phpstan-ignore-next-line */
file_get_contents(__DIR__.'/data/config.yml'),
Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE
);
Expand Down
7 changes: 0 additions & 7 deletions tests/Seo/SeoPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,4 @@ public function testHasMeta(): void
static::assertTrue($page->hasMeta('property', 'test'));
static::assertFalse($page->hasMeta('property', 'fake'));
}

public function testSetSeparator(): void
{
$page = new SeoPage();

static::assertInstanceOf(SeoPage::class, $page->setSeparator('-'));
}
}

0 comments on commit 1aa5c38

Please sign in to comment.