Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 81261e1

Browse files
make use of laravel di
1 parent 6bfdd1f commit 81261e1

18 files changed

+199
-173
lines changed

‎.gitignore‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
composer.lock
2-
/vendor
2+
/vendor
3+
4+
.phpunit.cache

‎bin/console.php‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
<?php
22

3-
// decoupled in own "*.php" file, so ECS, Rector and PHPStan works out of the box here
4-
53
declare(strict_types=1);
64

5+
use Rector\PhpParserNodesDocs\DependencyInjection\ContainerFactory;
6+
use Symfony\Component\Console\Application;
7+
use Symfony\Component\Console\Input\ArgvInput;
8+
use Symfony\Component\Console\Output\ConsoleOutput;
9+
10+
require_once __DIR__ . '/../vendor/autoload.php';
11+
12+
$containerFactory = new ContainerFactory();
13+
$container = $containerFactory->create();
14+
15+
/** @var Application $application */
16+
$application = $container->make(Application::class);
17+
18+
$input = new ArgvInput();
19+
$output = new ConsoleOutput();
20+
21+
$exitCode = $application->run($input, $output);
22+
exit($exitCode);

‎composer.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
"php": "^8.1",
1111
"symfony/console": "^6.3",
1212
"nikic/php-parser": "^4.16",
13-
"illuminate/container": "^10.15"
13+
"illuminate/container": "^10.15",
14+
"webmozart/assert": "^1.11"
1415
},
1516
"require-dev": {
1617
"symplify/easy-coding-standard": "^11.5",
1718
"phpstan/phpstan": "^1.10",
1819
"phpunit/phpunit": "^10.2",
19-
"rector/rector": "*"
20+
"rector/rector": "^0.17.6"
2021
},
2122
"autoload": {
2223
"psr-4": {

‎config/config.php‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎ecs.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
return static function (ECSConfig $ecsConfig): void {
99
$ecsConfig->paths([
10-
__DIR__ . '/config',
1110
__DIR__ . '/src',
1211
__DIR__ . '/tests',
1312
]);

‎phpstan.neon‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ parameters:
22
level: max
33

44
paths:
5-
- config
65
- src
76
- tests
87

98
ignoreErrors:
109
-
11-
message: '#Cannot cast array<string\>\|bool\|string\|null to string#'
10+
message: '#Cannot cast (.*?) to string#'
1211
path: src/Command/DumpNodesCommand.php

‎phpunit.xml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
bootstrap="vendor/autoload.php"
6+
colors="true"
7+
cacheDirectory=".phpunit.cache"
8+
>
9+
<testsuites>
10+
<testsuite name="unit">
11+
<directory>tests</directory>
12+
</testsuite>
13+
</testsuites>
14+
</phpunit>

‎rector.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->importNames();
11+
12+
$rectorConfig->paths([
13+
__DIR__ . '/src',
14+
__DIR__ . '/tests',
15+
]);
16+
17+
$rectorConfig->sets([
18+
LevelSetList::UP_TO_PHP_81
19+
]);
20+
};

‎src/Command/DumpNodesCommand.php‎

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
use Symfony\Component\Console\Input\InputInterface;
1111
use Symfony\Component\Console\Input\InputOption;
1212
use Symfony\Component\Console\Output\OutputInterface;
13-
use Symfony\Component\Console\Style\SymfonyStyle;
14-
use Symplify\PackageBuilder\Console\ShellCode;
15-
use Symplify\SmartFileSystem\SmartFileInfo;
16-
use Symplify\SmartFileSystem\SmartFileSystem;
1713

1814
final class DumpNodesCommand extends Command
1915
{
@@ -22,42 +18,16 @@ final class DumpNodesCommand extends Command
2218
*/
2319
private const OUTPUT_FILE = 'output-file';
2420

25-
/**
26-
* @var MarkdownNodeInfosPrinter
27-
*/
28-
private $markdownNodeInfosPrinter;
29-
30-
/**
31-
* @var NodeInfosFactory
32-
*/
33-
private $nodeInfosFactory;
34-
35-
/**
36-
* @var SmartFileSystem
37-
*/
38-
private $smartFileSystem;
39-
40-
/**
41-
* @var SymfonyStyle
42-
*/
43-
private $symfonyStyle;
44-
4521
public function __construct(
46-
MarkdownNodeInfosPrinter $markdownNodeInfosPrinter,
47-
NodeInfosFactory $nodeInfosFactory,
48-
SmartFileSystem $smartFileSystem,
49-
SymfonyStyle $symfonyStyle
22+
private readonly MarkdownNodeInfosPrinter $markdownNodeInfosPrinter,
23+
private readonly NodeInfosFactory $nodeInfosFactory,
5024
) {
51-
$this->markdownNodeInfosPrinter = $markdownNodeInfosPrinter;
52-
$this->nodeInfosFactory = $nodeInfosFactory;
53-
$this->smartFileSystem = $smartFileSystem;
54-
$this->symfonyStyle = $symfonyStyle;
55-
5625
parent::__construct();
5726
}
5827

5928
protected function configure(): void
6029
{
30+
$this->setName('dump-nodes');
6131
$this->setDescription('Dump nodes overview');
6232

6333
$this->addOption(
@@ -74,18 +44,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7444
$outputFile = (string) $input->getOption(self::OUTPUT_FILE);
7545

7646
$nodeInfos = $this->nodeInfosFactory->create();
77-
7847
$printedContent = $this->markdownNodeInfosPrinter->print($nodeInfos);
79-
$this->smartFileSystem->dumpFile($outputFile, $printedContent);
8048

81-
$outputFileFileInfo = new SmartFileInfo($outputFile);
82-
$message = sprintf(
49+
file_put_contents($outputFile, $printedContent);
50+
51+
$output->writeln(sprintf(
8352
'Documentation for "%d" PhpParser Nodes was generated to "%s"',
8453
count($nodeInfos),
85-
$outputFileFileInfo->getRelativeFilePathFromCwd()
86-
);
87-
$this->symfonyStyle->success($message);
54+
$outputFile
55+
));
8856

89-
return ShellCode::SUCCESS;
57+
return self::SUCCESS;
9058
}
9159
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\PhpParserNodesDocs\DependencyInjection;
6+
7+
use Illuminate\Container\Container;
8+
use Rector\PhpParserNodesDocs\Command\DumpNodesCommand;
9+
use Symfony\Component\Console\Application;
10+
11+
final class ContainerFactory
12+
{
13+
public function create(): Container
14+
{
15+
$container = new Container();
16+
17+
$container->singleton(Application::class, function (Container $container) {
18+
$application = new Application();
19+
20+
/** @var DumpNodesCommand $dumpNodesCommand */
21+
$dumpNodesCommand = $container->make(DumpNodesCommand::class);
22+
$application->add($dumpNodesCommand);
23+
24+
return $application;
25+
});
26+
27+
return $container;
28+
}
29+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /