Skip to content

Commit 629b14d

Browse files
feat: Add support for phparkitect
1 parent 5e4f28f commit 629b14d

8 files changed

Lines changed: 84 additions & 34 deletions

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
"symfony/process": "^5.4 || ^6.0"
2727
},
2828
"require-dev": {
29-
"myonlinestore/coding-standard": "^3.1",
29+
"myonlinestore/coding-standard": "dev-doctrine-cs-10",
30+
"doctrine/coding-standard": "10.0.x-dev",
3031
"phpunit/phpunit": "^9.5",
3132
"roave/infection-static-analysis-plugin": "^1.19",
3233
"roave/security-advisories": "dev-latest",
3334
"vimeo/psalm": "^4.23",
3435
"phpstan/phpstan": "^1.7",
35-
"phpstan/phpstan-phpunit": "^1.1"
36+
"phpstan/phpstan-phpunit": "^1.1",
37+
"phparkitect/phparkitect": "^0.2.21"
3638
},
3739
"bin": [
3840
"bin/devtools"

phparkitect.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Arkitect\ClassSet;
5+
use Arkitect\CLI\Config;
6+
use Arkitect\Expression\ForClasses\Extend;
7+
use Arkitect\Expression\ForClasses\HaveNameMatching;
8+
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
9+
use Arkitect\Rules\Rule;
10+
use PHPUnit\Framework\TestCase;
11+
12+
return static function (Config $config): void {
13+
$srcClassSet = ClassSet::fromDir(__DIR__ . '/src');
14+
15+
$commandNamingRule = Rule::allClasses()
16+
->that(new ResideInOneOfTheseNamespaces('MyOnlineStore\DevTools\Command'))
17+
->should(new HaveNameMatching('*Command'))
18+
->because('we want uniform naming for console commands');
19+
20+
$config->add($srcClassSet, $commandNamingRule);
21+
22+
$testClassSet = ClassSet::fromDir(__DIR__ . '/tests');
23+
24+
$testNamingRule = Rule::allClasses()
25+
->that(new Extend(TestCase::class))
26+
->should(new HaveNameMatching('*Test'))
27+
->because('that is a PHPUnit naming convention');
28+
29+
$config->add($testClassSet, $testNamingRule);
30+
};

src/Command/DevToolsCommand.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function configure(): void
2424
'format',
2525
null,
2626
InputOption::VALUE_OPTIONAL,
27-
'Output format to use (by supported commands).'
27+
'Output format to use (by supported commands).',
2828
);
2929
}
3030

@@ -44,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4444
$exitCode |= $process->wait(
4545
static function (string $_type, string $buffer) use ($output): void {
4646
$output->write($buffer);
47-
}
47+
},
4848
);
4949
}
5050

@@ -56,9 +56,7 @@ protected function getProcess(InputInterface $input): Process
5656
throw new \RuntimeException('Either implement getProcess() or getMultiProcess()');
5757
}
5858

59-
/**
60-
* @return list<Process>
61-
*/
59+
/** @return list<Process> */
6260
protected function getMultiProcess(InputInterface $input): array
6361
{
6462
return [];

src/Command/DoctrineMigrationsCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
#[AsCommand('doctrine-migrations', 'Doctrine Migrations, always runs in test environment')]
1212
final class DoctrineMigrationsCommand extends DevToolsCommand
1313
{
14-
/**
15-
* @inheritDoc
16-
*/
14+
/** @inheritDoc */
1715
protected function getMultiProcess(InputInterface $input): array
1816
{
1917
return [

src/Command/PhpArkitectCommand.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace MyOnlineStore\DevTools\Command;
5+
6+
use MyOnlineStore\DevTools\Configuration;
7+
use Symfony\Component\Console\Attribute\AsCommand;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Process\Process;
10+
11+
#[AsCommand('phparkitect', 'PHPArkitect')]
12+
final class PhpArkitectCommand extends DevToolsCommand
13+
{
14+
protected function getProcess(InputInterface $input): Process
15+
{
16+
return new Process(
17+
[$this->withVendorBinPath('phparkitect'), 'check'],
18+
timeout: null,
19+
);
20+
}
21+
22+
public static function isAvailable(Configuration $configuration): bool
23+
{
24+
if (!\is_file($configuration->getRootDir() . 'vendor/bin/phparkitect')) {
25+
return false;
26+
}
27+
28+
return \is_file($configuration->getRootDir() . 'phparkitect.php');
29+
}
30+
}

src/Configuration.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ final class Configuration
1515
];
1616

1717
/** @var array<string, class-string<DevToolsCommand>>|null */
18-
private ?array $enabledTools = null;
18+
private array|null $enabledTools = null;
1919

2020
/** @var list<string>|null */
21-
private ?array $phpVersions = null;
21+
private array|null $phpVersions = null;
2222

2323
private string $rootDir;
24-
private ?string $threads = null;
24+
private string|null $threads = null;
2525

2626
public function __construct()
2727
{
@@ -42,9 +42,7 @@ public function __construct()
4242
throw new \RuntimeException('Unable to determine project root');
4343
}
4444

45-
/**
46-
* @return array<string, class-string<DevToolsCommand>>
47-
*/
45+
/** @return array<string, class-string<DevToolsCommand>> */
4846
public function getEnabledTools(): array
4947
{
5048
if (null === $this->enabledTools) {
@@ -54,9 +52,7 @@ public function getEnabledTools(): array
5452
return $this->enabledTools;
5553
}
5654

57-
/**
58-
* @return list<string>
59-
*/
55+
/** @return list<string> */
6056
public function getPhpVersions(): array
6157
{
6258
if (null === $this->phpVersions) {
@@ -87,13 +83,11 @@ private function determineThreads(): string
8783
'Linux' => Process::fromShellCommandline('nproc')->mustRun()->getOutput(),
8884
'Darwin' => Process::fromShellCommandline('sysctl -n hw.logicalcpu')->mustRun()->getOutput(),
8985
default => '2',
90-
}
86+
},
9187
);
9288
}
9389

94-
/**
95-
* @return list<string>
96-
*/
90+
/** @return list<string> */
9791
private function gatherPhpVersions(): array
9892
{
9993
if (false === $composerJson = \file_get_contents($this->rootDir . 'composer.json')) {
@@ -124,9 +118,7 @@ private function gatherPhpVersions(): array
124118
return $versions;
125119
}
126120

127-
/**
128-
* @return list<class-string<DevToolsCommand>>
129-
*/
121+
/** @return list<class-string<DevToolsCommand>> */
130122
private function gatherAvailableCommands(): array
131123
{
132124
$commands = [];
@@ -142,9 +134,7 @@ private function gatherAvailableCommands(): array
142134
return $commands;
143135
}
144136

145-
/**
146-
* @return array<string, class-string<DevToolsCommand>>
147-
*/
137+
/** @return array<string, class-string<DevToolsCommand>> */
148138
private function gatherEnabledTools(): array
149139
{
150140
$enabledTools = [];

src/DevTools.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use MyOnlineStore\DevTools\Command\LintYamlCommand;
1212
use MyOnlineStore\DevTools\Command\ListPhpVersionsCommand;
1313
use MyOnlineStore\DevTools\Command\ListToolsCommand;
14+
use MyOnlineStore\DevTools\Command\PhpArkitectCommand;
1415
use MyOnlineStore\DevTools\Command\PhpStanCommand;
1516
use MyOnlineStore\DevTools\Command\PhpUnitCommand;
1617
use MyOnlineStore\DevTools\Command\PsalmCommand;
@@ -24,9 +25,7 @@ public function __construct(
2425
) {
2526
}
2627

27-
/**
28-
* @return list<Command>
29-
*/
28+
/** @return list<Command> */
3029
public function getCommands(): array
3130
{
3231
return [
@@ -38,6 +37,7 @@ public function getCommands(): array
3837
new LintYamlCommand($this->configuration),
3938
new ListToolsCommand($this->configuration),
4039
new ListPhpVersionsCommand($this->configuration),
40+
new PhpArkitectCommand($this->configuration),
4141
new PhpStanCommand($this->configuration),
4242
new PhpUnitCommand($this->configuration),
4343
new PsalmCommand($this->configuration),

tests/DevToolsTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use MyOnlineStore\DevTools\Command\LintYamlCommand;
1212
use MyOnlineStore\DevTools\Command\ListPhpVersionsCommand;
1313
use MyOnlineStore\DevTools\Command\ListToolsCommand;
14+
use MyOnlineStore\DevTools\Command\PhpArkitectCommand;
1415
use MyOnlineStore\DevTools\Command\PhpStanCommand;
1516
use MyOnlineStore\DevTools\Command\PhpUnitCommand;
1617
use MyOnlineStore\DevTools\Command\PsalmCommand;
@@ -27,7 +28,7 @@ final class DevToolsTest extends TestCase
2728
protected function setUp(): void
2829
{
2930
$this->devTools = new DevTools(
30-
$this->configuration = new Configuration()
31+
$this->configuration = new Configuration(),
3132
);
3233
}
3334

@@ -43,12 +44,13 @@ public function testGetCommands(): void
4344
new LintYamlCommand($this->configuration),
4445
new ListToolsCommand($this->configuration),
4546
new ListPhpVersionsCommand($this->configuration),
47+
new PhpArkitectCommand($this->configuration),
4648
new PhpStanCommand($this->configuration),
4749
new PhpUnitCommand($this->configuration),
4850
new PsalmCommand($this->configuration),
4951
new RoaveInfectionCommand($this->configuration),
5052
],
51-
$this->devTools->getCommands()
53+
$this->devTools->getCommands(),
5254
);
5355
}
5456

0 commit comments

Comments
 (0)