Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ci/check_keep_fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Nette\Utils\Strings;
use Rector\Core\Testing\PHPUnit\FixtureSplitter;
use Rector\Core\Testing\ValueObject\SplitLine;
use Symfony\Component\Finder\Finder;
use Symplify\PackageBuilder\Console\ShellCode;
use Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory;
Expand All @@ -29,12 +30,12 @@

/** @var SmartFileInfo $smartFileInfo */
foreach ($smartFileInfos as $smartFileInfo) {
if (! Strings::match($smartFileInfo->getContents(), FixtureSplitter::SPLIT_LINE)) {
if (! Strings::match($smartFileInfo->getContents(), SplitLine::SPLIT_LINE)) {
continue;
}

// original → expected
[$originalContent, $expectedContent] = Strings::split($smartFileInfo->getContents(), FixtureSplitter::SPLIT_LINE);
[$originalContent, $expectedContent] = Strings::split($smartFileInfo->getContents(), SplitLine::SPLIT_LINE);
if ($originalContent !== $expectedContent) {
continue;
}
Expand All @@ -48,8 +49,8 @@

$symfonyStyle->warning(sprintf(
'These files have same content before "%s" and after it. Remove the content after "%s"',
FixtureSplitter::SPLIT_LINE,
FixtureSplitter::SPLIT_LINE
SplitLine::SPLIT_LINE,
SplitLine::SPLIT_LINE
));

$symfonyStyle->listing($errors);
Expand Down
77 changes: 49 additions & 28 deletions ci/check_services_in_yaml_configs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,63 @@

require __DIR__ . '/../vendor/autoload.php';

$yamlConfigFileProvider = new YamlConfigFileProvider();
$serviceConfigurationValidator = new ServiceConfigurationValidator();
$serviceExistenceConfigChecker = new ServiceExistenceConfigChecker();
$serviceExistenceConfigChecker->check();

foreach ($yamlConfigFileProvider->provider() as $configFileInfo) {
$yamlContent = Yaml::parseFile($configFileInfo->getRealPath());
if (! isset($yamlContent['services'])) {
continue;
}
final class ServiceExistenceConfigChecker
{
/**
* @var YamlConfigFileProvider
*/
private $yamlConfigFileProvider;

foreach ($yamlContent['services'] as $service => $serviceConfiguration) {
// configuration → skip
if (Strings::startsWith($service, '_')) {
continue;
}
/**
* @var ServiceConfigurationValidator
*/
private $serviceConfigurationValidator;

// autodiscovery → skip
if (Strings::endsWith($service, '\\')) {
continue;
}
public function __construct()
{
$this->yamlConfigFileProvider = new YamlConfigFileProvider();
$this->serviceConfigurationValidator = new ServiceConfigurationValidator();
}

if (! ClassExistenceStaticHelper::doesClassLikeExist($service)) {
throw new ShouldNotHappenException(sprintf(
'Service "%s" from config "%s" was not found. Check if it really exists or is even autoload, please',
$service,
$configFileInfo->getRealPath()
));
public function check(): void
{
foreach ($this->yamlConfigFileProvider->provider() as $configFileInfo) {
$yamlContent = Yaml::parseFile($configFileInfo->getRealPath());
if (! isset($yamlContent['services'])) {
continue;
}

foreach ($yamlContent['services'] as $service => $serviceConfiguration) {
// configuration → skip
if (Strings::startsWith($service, '_')) {
continue;
}

// autodiscovery → skip
if (Strings::endsWith($service, '\\')) {
continue;
}

if (! ClassExistenceStaticHelper::doesClassLikeExist($service)) {
throw new ShouldNotHappenException(sprintf(
'Service "%s" from config "%s" was not found. Check if it really exists or is even autoload, please',
$service,
$configFileInfo->getRealPath()
));
}

$this->serviceConfigurationValidator->validate($service, $serviceConfiguration, $configFileInfo);
}
}

$serviceConfigurationValidator->validate($service, $serviceConfiguration, $configFileInfo);
echo 'All configs have existing services - good job!' . PHP_EOL;
}
}


class YamlConfigFileProvider
final class YamlConfigFileProvider
{
/**
* @return SplFileInfo[]
Expand All @@ -59,7 +82,7 @@ public function provider(): array
}
}

class ServiceConfigurationValidator
final class ServiceConfigurationValidator
{
public function validate(string $serviceClass, $configuration, SplFileInfo $configFileInfo): void
{
Expand Down Expand Up @@ -119,5 +142,3 @@ private function resolveClassConstructorArgumentNames(string $class): array
return $constructorParameterNames;
}
}

echo 'All configs have existing services - good job!' . PHP_EOL;
1 change: 0 additions & 1 deletion ecs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ services:

parameters:
paths:
- "ci"
- "bin"
- "src"
- "packages"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\Contract\PhpDocNode;

use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;

interface ShortNameAwareTagInterface extends PhpDocTagValueNode
{
public function getShortName(): string;
}
6 changes: 3 additions & 3 deletions packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
use Rector\BetterPhpDocParser\Annotation\AnnotationNaming;
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\SpacelessPhpDocTagNode;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode;
use Rector\Core\Exception\NotImplementedException;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\PHPStan\TypeComparator;
Expand Down Expand Up @@ -104,9 +104,9 @@ public function addPhpDocTagNode(PhpDocChildNode $phpDocChildNode): void
$this->phpDocNode->children[] = $phpDocChildNode;
}

public function addTagValueNodeWithShortName(AbstractTagValueNode $tagValueNode): void
public function addTagValueNodeWithShortName(ShortNameAwareTagInterface $shortNameAwareTag): void
{
$spacelessPhpDocTagNode = new SpacelessPhpDocTagNode($tagValueNode::SHORT_NAME, $tagValueNode);
$spacelessPhpDocTagNode = new SpacelessPhpDocTagNode($shortNameAwareTag->getShortName(), $shortNameAwareTag);
$this->addPhpDocTagNode($spacelessPhpDocTagNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine;

use Rector\BetterPhpDocParser\Contract\Doctrine\DoctrineTagNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode;

abstract class AbstractDoctrineTagValueNode extends AbstractTagValueNode implements DoctrineTagNodeInterface
abstract class AbstractDoctrineTagValueNode extends AbstractTagValueNode implements DoctrineTagNodeInterface, ShortNameAwareTagInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

final class EntityTagValueNode extends AbstractDoctrineTagValueNode
{
/**
* @var string
*/
public const SHORT_NAME = '@ORM\Entity';

/**
* @var string|null
*/
Expand Down Expand Up @@ -53,4 +48,9 @@ public function removeRepositoryClass(): void
{
$this->repositoryClass = null;
}

public function getShortName(): string
{
return '@ORM\Entity';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

final class IndexTagValueNode extends AbstractIndexTagValueNode
{
/**
* @var string
*/
public const SHORT_NAME = '@ORM\Index';

public function getTag(): ?string
{
return $this->tag ?: self::SHORT_NAME;
return $this->tag ?: $this->getShortName();
}

public function getShortName(): string
{
return '@ORM\Index';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

final class InheritanceTypeTagValueNode extends AbstractDoctrineTagValueNode
{
/**
* @var string
*/
public const SHORT_NAME = '@ORM\InheritanceType';

/**
* @var string|null
*/
Expand All @@ -36,4 +31,9 @@ public function __toString(): string

return '(value="' . $this->value . '")';
}

public function getShortName(): string
{
return '@ORM\InheritanceType';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

final class TableTagValueNode extends AbstractDoctrineTagValueNode
{
/**
* @var string
*/
public const SHORT_NAME = '@ORM\Table';

/**
* @var string|null
*/
Expand Down Expand Up @@ -152,4 +147,9 @@ public function getName(): ?string
{
return $this->name;
}

public function getShortName(): string
{
return '@ORM\Table';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

final class UniqueConstraintTagValueNode extends AbstractIndexTagValueNode
{
/**
* @var string
*/
public const SHORT_NAME = '@ORM\UniqueConstraint';

public function getTag(): ?string
{
return $this->tag ?: self::SHORT_NAME;
return $this->tag ?: $this->getShortName();
}

public function getShortName(): string
{
return '@ORM\UniqueConstraint';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

final class ColumnTagValueNode extends AbstractDoctrineTagValueNode
{
/**
* @var string
*/
public const SHORT_NAME = '@ORM\Column';

/**
* @var string|null
*/
Expand Down Expand Up @@ -167,4 +162,9 @@ public function isNullable(): ?bool
{
return $this->nullable;
}

public function getShortName(): string
{
return '@ORM\Column';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

final class CustomIdGeneratorTagValueNode extends AbstractDoctrineTagValueNode
{
/**
* @var string
*/
public const SHORT_NAME = '@ORM\CustomIdGenerator';

/**
* @var string
*/
Expand All @@ -28,4 +23,9 @@ public function __toString(): string
{
return sprintf('(class="%s")', $this->class);
}

public function getShortName(): string
{
return '@ORM\CustomIdGenerator';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

final class GeneratedValueTagValueNode extends AbstractDoctrineTagValueNode
{
/**
* @var string
*/
public const SHORT_NAME = '@ORM\GeneratedValue';

/**
* @var string
*/
Expand All @@ -27,4 +22,9 @@ public function __toString(): string
{
return sprintf('(strategy="%s")', $this->strategy);
}

public function getShortName(): string
{
return '@ORM\GeneratedValue';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

final class IdTagValueNode extends AbstractDoctrineTagValueNode
{
/**
* @var string
*/
public const SHORT_NAME = '@ORM\Id';

public function __toString(): string
{
return '';
}

public function getShortName(): string
{
return '@ORM\Id';
}
}
Loading