Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f25c8e1
Add PHPCS scaffold tool
ghostwriter Mar 6, 2026
921ed61
Refactor and restructure
ghostwriter Mar 7, 2026
44d96c6
Refactor scaffold script and add tests
ghostwriter Mar 10, 2026
9f601c4
Add PHPUnit executionOrder and coverage reporting
ghostwriter Mar 11, 2026
c364675
Update composer.json metadata and scripts
ghostwriter Mar 11, 2026
db3a411
Enable xdebug coverage in CI workflow
ghostwriter Mar 11, 2026
dcc2a99
Revert "Add PHPUnit executionOrder and coverage reporting"
ghostwriter Mar 11, 2026
f6fe976
Replace createMock with getMockBuilder to PHPUnit 4.x
ghostwriter Mar 11, 2026
76baf3e
Use getMockBuilder for PHPUnit mocks
ghostwriter Mar 11, 2026
9056292
Add unreadable stream wrapper for filesystem tests
ghostwriter Mar 11, 2026
471f1b9
Skip template test for PHP <5.6
ghostwriter Mar 11, 2026
59dfd09
Use DIRECTORY_SEPARATOR
ghostwriter Mar 11, 2026
2520064
cross-platform compatibility
ghostwriter Mar 11, 2026
87d4ffa
Improve directory creation error handling and tests
ghostwriter Mar 11, 2026
565b1a6
Refactor scaffold to use DI container and an event-driven architecture
ghostwriter Apr 26, 2026
30ecf09
Revert composer normalize
ghostwriter Apr 26, 2026
199c839
enable logging phpunit code coverage
ghostwriter Apr 26, 2026
9cf19d4
Fix phpcs issues
ghostwriter Apr 27, 2026
6f63ab9
Revert changes to ci
ghostwriter Apr 27, 2026
2a431ee
Revert "enable logging phpunit code coverage"
ghostwriter Apr 27, 2026
e5b5230
Use createMockObject to fix failing tests
ghostwriter Apr 27, 2026
661a8e0
Fix generics and type annotations and cleanup tests
ghostwriter Apr 27, 2026
bbab9db
Fix "Missing short description in doc comment"
ghostwriter Apr 27, 2026
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
71 changes: 71 additions & 0 deletions Scripts/Scaffold/Collection/StandardCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/**
* PHPCSDevTools, tools for PHP_CodeSniffer sniff developers.
*
* @package PHPCSDevTools
* @copyright 2019 PHPCSDevTools Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSDevTools
*/

namespace PHPCSDevTools\Scripts\Scaffold\Collection;

use PHPCSDevTools\Scripts\Scaffold\Exception\ScaffolderException;
use PHPCSDevTools\Scripts\Scaffold\Standard\NameInterface;
use PHPCSDevTools\Scripts\Scaffold\StandardInterface;

/**
* Represents a collection of standard.
*/
final class StandardCollection implements StandardCollectionInterface
{

/**
* The standards in the collection, keyed by standard name.
*
* @var array<non-empty-string, StandardInterface>
*/
private $standards = [];

/**
* Add the standard metadata to the collection.
*
* @param StandardInterface $standard The standard metadata to add
*
* @return void
*/
public function add(StandardInterface $standard)
{
$this->standards[$standard->getName()->toString()] = $standard;
}

/**
* Get the standard metadata for a given standard name.
*
* @param NameInterface $standardName The name of the standard
*
* @return StandardInterface
*/
public function get(NameInterface $standardName)
{
if (isset($this->standards[$standardName->toString()]) === false) {
throw new ScaffolderException(\sprintf(
'Standard "%s" not found in collection.',
$standardName->toString()
));
}

return $this->standards[$standardName->toString()];
}

/**
* Get all discovered standards keyed by standard name.
*
* @return array<non-empty-string, StandardInterface>
*/
public function toArray()
{
return $this->standards;
}
}
47 changes: 47 additions & 0 deletions Scripts/Scaffold/Collection/StandardCollectionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* PHPCSDevTools, tools for PHP_CodeSniffer sniff developers.
*
* @package PHPCSDevTools
* @copyright 2019 PHPCSDevTools Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSDevTools
*/

namespace PHPCSDevTools\Scripts\Scaffold\Collection;

use PHPCSDevTools\Scripts\Scaffold\Standard\NameInterface;
use PHPCSDevTools\Scripts\Scaffold\StandardInterface;

/**
* Interface StandardCollectionInterface.
*/
interface StandardCollectionInterface
{

/**
* Add the standard metadata to the collection.
*
* @param StandardInterface $standard The standard metadata to add
*
* @return void
*/
public function add(StandardInterface $standard);

/**
* Get the standard metadata for a given standard name.
*
* @param NameInterface $standardName The name of the standard
*
* @return StandardInterface
*/
public function get(NameInterface $standardName);

/**
* Get all discovered standards keyed by standard name.
*
* @return array<non-empty-string, StandardInterface>
*/
public function toArray();
}
79 changes: 79 additions & 0 deletions Scripts/Scaffold/Console/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/**
* PHPCSDevTools, tools for PHP_CodeSniffer sniff developers.
*
* @package PHPCSDevTools
* @copyright 2019 PHPCSDevTools Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSDevTools
*/

namespace PHPCSDevTools\Scripts\Scaffold\Console;

use PHPCSDevTools\Scripts\Scaffold\DispatcherInterface;
use PHPCSDevTools\Scripts\Scaffold\DotSeparatedSniff;
use PHPCSDevTools\Scripts\Scaffold\Event\ApplicationConstructedEvent;
use PHPCSDevTools\Scripts\Scaffold\Event\ApplicationFinishedEvent;
use PHPCSDevTools\Scripts\Scaffold\Event\ApplicationStartedEvent;
use PHPCSDevTools\Scripts\Scaffold\Event\ApplicationStartingEvent;
use PHPCSDevTools\Scripts\Scaffold\Event\Exception\ApplicationExceptionEvent;
use PHPCSDevTools\Scripts\Scaffold\Exception\ScaffolderException;
use PHPCSDevTools\Scripts\Scaffold\WorkspaceInterface;
use PHPCSDevTools\Tests\Scaffold\ScaffolderTest;

/**
* Coordinates the generation of scaffold files for a sniff.
*
* @see ScaffolderTest
*/
final class Application implements ApplicationInterface
{

/**
* The event dispatcher to use for dispatching events.
*
* @var DispatcherInterface
*/
private $dispatcher;

/**
* Create a new application instance.
*
* @param DispatcherInterface $dispatcher the event dispatcher to use for dispatching events
*/
public function __construct(DispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
}

/**
* Run the application with the given arguments.
*
* @param RequestInterface $request the validated application arguments
* @param WorkspaceInterface $workspace the workspace in which the application should run
*
* @throws ScaffolderException if an error occurs during scaffolding
*
* @return void
*/
public function run(RequestInterface $request, WorkspaceInterface $workspace)
{
$this->dispatcher->dispatch(new ApplicationConstructedEvent($workspace));

$this->dispatcher->dispatch(new ApplicationStartingEvent($request));

$dotSeparatedSniff = DotSeparatedSniff::fromRequest($request);

$exitCode = 1;

try {
$this->dispatcher->dispatch(new ApplicationStartedEvent($dotSeparatedSniff, $workspace));
$exitCode = 0;
} catch (\Exception $exception) {
$this->dispatcher->dispatch(new ApplicationExceptionEvent($dotSeparatedSniff, $exception, $workspace));
}

$this->dispatcher->dispatch(new ApplicationFinishedEvent($exitCode, $dotSeparatedSniff, $workspace));
}
}
34 changes: 34 additions & 0 deletions Scripts/Scaffold/Console/ApplicationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* PHPCSDevTools, tools for PHP_CodeSniffer sniff developers.
*
* @package PHPCSDevTools
* @copyright 2019 PHPCSDevTools Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSDevTools
*/

namespace PHPCSDevTools\Scripts\Scaffold\Console;

use PHPCSDevTools\Scripts\Scaffold\Exception\ScaffolderException;
use PHPCSDevTools\Scripts\Scaffold\WorkspaceInterface;

/**
* Defines the scaffold orchestration entry point.
*/
interface ApplicationInterface
{

/**
* Run the application with the given arguments.
*
* @param RequestInterface $request the validated application arguments
* @param WorkspaceInterface $workspace the workspace in which the application should run
*
* @throws ScaffolderException if an error occurs during scaffolding
*
* @return void
*/
public function run(RequestInterface $request, WorkspaceInterface $workspace);
}
81 changes: 81 additions & 0 deletions Scripts/Scaffold/Console/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/**
* PHPCSDevTools, tools for PHP_CodeSniffer sniff developers.
*
* @package PHPCSDevTools
* @copyright 2019 PHPCSDevTools Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSDevTools
*/

namespace PHPCSDevTools\Scripts\Scaffold\Console;

use PHPCSDevTools\Tests\Scaffold\RequestTest;

/**
* Represents the validated inputs needed to run the scaffold application.
*
* @see RequestTest
*/
final class Request implements RequestInterface
{

/**
* The command line arguments.
*
* @var list<non-empty-string>
*/
private $arguments;

/**
* Create a new application arguments value object.
*
* @param list<string> $arguments the command line arguments passed to the application
*
* @throws \InvalidArgumentException if any argument is not a non-empty string
*/
public function __construct(array $arguments)
{
foreach ($arguments as $argument) {
if (\is_string($argument) === false) {
throw new \InvalidArgumentException(\sprintf(
'Each argument must be a string. "%s" given.',
\is_object($argument) ? \get_class($argument) : \gettype($argument)
));
}

if (\trim($argument) === '') {
throw new \InvalidArgumentException('Each argument must be a non-empty-string.');
}
}

$this->arguments = $arguments;
}

/**
* Get the command.
*
* @throws \InvalidArgumentException if no arguments are provided
*
* @return non-empty-string
*/
public function getCommand()
{
foreach ($this->arguments as $argument) {
return $argument;
}

throw new \InvalidArgumentException('At least one argument is required to determine the command.');
}

/**
* Get command line arguments as an array.
*
* @return list<non-empty-string>
*/
public function toArray()
{
return $this->arguments;
}
}
33 changes: 33 additions & 0 deletions Scripts/Scaffold/Console/RequestInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* PHPCSDevTools, tools for PHP_CodeSniffer sniff developers.
*
* @package PHPCSDevTools
* @copyright 2019 PHPCSDevTools Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSDevTools
*/

namespace PHPCSDevTools\Scripts\Scaffold\Console;

/**
* Defines the validated inputs needed to run the scaffold application.
*/
interface RequestInterface
{

/**
* Get the command to run.
*
* @return non-empty-string
*/
public function getCommand();

/**
* Get the validated command line arguments.
*
* @return list<non-empty-string>
*/
public function toArray();
}
Loading
Loading