Skip to content

Commit

Permalink
1st step rebuilding: add interfaces, refactors of traits, update over…
Browse files Browse the repository at this point in the history
…head
  • Loading branch information
Jeroen-G committed Mar 20, 2023
1 parent 98dc78d commit ac44bb6
Show file tree
Hide file tree
Showing 25 changed files with 352 additions and 311 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Expand Up @@ -13,10 +13,10 @@ jobs:

strategy:
matrix:
php: [8.0, 8.1]
php: [8.0, 8.1, 8.2]
experimental: [ false ]
include:
- php: 8.2
- php: 8.3
experimental: true

name: PHP${{ matrix.php }}
Expand Down Expand Up @@ -46,4 +46,4 @@ jobs:
run: vendor/bin/phpunit --testsuite unit --testdox --colors=always

- name: Execute mutation tests
run: vendor/bin/infection --threads=4 --min-covered-msi=100 --min-msi=100
run: vendor/bin/infection --threads=4 --min-covered-msi=50 --min-msi=50
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -16,10 +16,10 @@ cs:
make codestyle

codestyle: ## Check the codestyle
./vendor/bin/ecs check --config=easy-coding-standard.php .
./vendor/bin/ecs check --config=easy-coding-standard.php

codestyle-fix: ## Fix your mess
./vendor/bin/ecs check --fix --config=easy-coding-standard.php .
./vendor/bin/ecs check --fix --config=easy-coding-standard.php

test: ## Run PHPUnit with coverage
@echo "\n=== Running unit tests ===\n"
Expand All @@ -29,6 +29,6 @@ test: ## Run PHPUnit with coverage

infection: ## Run InfectionPHP with coverage
@echo "\n=== Running unit tests ===\n"
XDEBUG_MODE=coverage vendor/bin/infection --threads=4 --min-covered-msi=100 --min-msi=100
XDEBUG_MODE=coverage vendor/bin/infection --threads=4 --min-covered-msi=50 --min-msi=50
@echo "\n=== Click the link below to see the mutation coverage report ===\n"
@echo "report/infection.html"
8 changes: 7 additions & 1 deletion composer.json
Expand Up @@ -17,7 +17,7 @@
}
],
"require": {
"php": "^8.0|^8.1",
"php": "8.0.*||8.1.*||8.2.*",
"ext-zip": "*",
"ext-json": "*",
"illuminate/support": "^8.0|^9.0",
Expand Down Expand Up @@ -46,5 +46,11 @@
"JeroenG\\Packager\\PackagerServiceProvider"
]
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false,
"infection/extension-installer": false
}
}
}
6 changes: 3 additions & 3 deletions easy-coding-standard.php
Expand Up @@ -12,10 +12,10 @@
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\CodingStandard\Fixer\Strict\BlankLineAfterStrictTypesFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
return static function (ECSConfig $containerConfigurator): void {
$services = $containerConfigurator->services();
$parameters = $containerConfigurator->parameters();

Expand All @@ -32,5 +32,5 @@
$services->set(StrictParamFixer::class);

$parameters->set('sets', ['clean-code', 'psr12']);
$parameters->set('exclude_files', ['node_modules/*', 'vendor/*', 'docs/*']);
$parameters->set('exclude_files', ['node_modules/*', 'vendor/*', 'docs/*', 'testbench/*']);
};
31 changes: 17 additions & 14 deletions phpunit.xml
@@ -1,17 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>src/</directory>
</include>
<report>
<html outputDirectory="./report" lowUpperBound="50" highLowerBound="80"/>
</report>
</coverage>
<testsuites>
<testsuite name="Packager">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<logging/>
<coverage>
<include>
<directory>src/</directory>
</include>
<report>
<html outputDirectory="./report" lowUpperBound="50" highLowerBound="80"/>
</report>
</coverage>
<testsuites>
<testsuite name="unit">
<directory suffix=".php">./tests/Unit</directory>
</testsuite>
<testsuite name="integration">
<directory suffix=".php">./tests/Integration</directory>
</testsuite>
</testsuites>
<logging/>
</phpunit>
19 changes: 19 additions & 0 deletions src/CommandRunner.php
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace JeroenG\Packager;

use Symfony\Component\Process\Process;

final class CommandRunner implements CommandRunnerInterface
{
public function run(array $commandInput): bool
{
$process = new Process($commandInput, base_path());
$process->setTimeout((float) config('packager.timeout'));
$process->run();

return $process->getExitCode() === 0;
}
}
10 changes: 10 additions & 0 deletions src/CommandRunnerInterface.php
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace JeroenG\Packager;

interface CommandRunnerInterface
{
public function run(array $commandInput): bool;
}
30 changes: 12 additions & 18 deletions src/Commands/GetPackage.php
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Console\Command;
use JeroenG\Packager\Conveyor;
use JeroenG\Packager\FileHandlerInterface;
use JeroenG\Packager\ProgressBar;
use JeroenG\Packager\Wrapping;

Expand All @@ -22,7 +23,6 @@ class GetPackage extends Command
{url : The url of the repository}
{vendor? : The vendor part of the namespace}
{name? : The name of package for the namespace}
{--host=github : Download from github or bitbucket?}
{--branch=master : The branch to download}';

protected $description = 'Retrieve an existing package from Github or Bitbucket.';
Expand All @@ -37,11 +37,14 @@ class GetPackage extends Command
*/
protected Wrapping $wrapping;

public function __construct(Conveyor $conveyor, Wrapping $wrapping)
protected FileHandlerInterface $fileHandler;

public function __construct(Conveyor $conveyor, Wrapping $wrapping, FileHandlerInterface $fileHandler)
{
parent::__construct();
$this->conveyor = $conveyor;
$this->wrapping = $wrapping;
$this->fileHandler = $fileHandler;
}

public function handle(): void
Expand All @@ -50,11 +53,7 @@ public function handle(): void
$this->startProgressBar(4);

// Common variables
if ($this->option('host') === 'bitbucket') {
$origin = mb_strtolower(rtrim($this->argument('url'), '/')).'/branch/'.$this->option('branch').'.zip';
} else {
$origin = mb_strtolower(rtrim($this->argument('url'), '/')).'/archive/'.$this->option('branch').'.zip';
}
$origin = mb_strtolower(rtrim($this->argument('url'), '/')).'/archive/'.$this->option('branch').'.zip';
$pieces = explode('/', $origin);
if (is_null($this->argument('vendor')) || is_null($this->argument('name'))) {
$this->conveyor->vendor($pieces[3]);
Expand All @@ -66,27 +65,22 @@ public function handle(): void

// Start creating the package
$this->info('Creating package '.$this->conveyor->vendor().'\\'.$this->conveyor->package().'...');
$this->conveyor->checkIfPackageExists();
$this->fileHandler->checkIfPackageExists($this->conveyor->vendor(), $this->conveyor->package());
$this->makeProgress();

// Create the package directory
$this->info('Creating packages directory...');
$this->conveyor->makeDir($this->conveyor->packagesPath());
$this->fileHandler->makeDir($this->fileHandler->packagesPath());
$this->makeProgress();

// Create the vendor directory
$this->info('Creating vendor...');
$this->conveyor->makeDir($this->conveyor->vendorPath());
$this->fileHandler->makeDir($this->fileHandler->vendorPath($this->conveyor->vendor()));
$this->makeProgress();

// Get the repo from Github or Bitbucket
if ($this->option('host') === ' bitbucket') {
$this->info('Downloading from Bitbucket...');
$this->conveyor->downloadFromBitbucket($origin, $pieces[4], $this->option('branch'));
} else {
$this->info('Downloading from Github...');
$this->conveyor->downloadFromGithub($origin, $pieces[4], $this->option('branch'));
}
$this->info('Downloading from Github...');
$this->conveyor->downloadFromGithub($origin, $pieces[4], $this->option('branch'));

$this->makeProgress();

// Install the package
Expand Down
14 changes: 9 additions & 5 deletions src/Commands/GitPackage.php
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use JeroenG\Packager\Conveyor;
use JeroenG\Packager\FileHandlerInterface;
use JeroenG\Packager\ProgressBar;
use JeroenG\Packager\Wrapping;

Expand Down Expand Up @@ -36,11 +37,14 @@ class GitPackage extends Command
*/
protected Wrapping $wrapping;

public function __construct(Conveyor $conveyor, Wrapping $wrapping)
protected FileHandlerInterface $fileHandler;

public function __construct(Conveyor $conveyor, Wrapping $wrapping, FileHandlerInterface $fileHandler)
{
parent::__construct();
$this->conveyor = $conveyor;
$this->wrapping = $wrapping;
$this->fileHandler = $fileHandler;
}

public function handle(): void
Expand All @@ -61,16 +65,16 @@ public function handle(): void

// Start creating the package
$this->info('Creating package '.$this->conveyor->vendor().'\\'.$this->conveyor->package().'...');
$this->conveyor->checkIfPackageExists();
$this->fileHandler->checkIfPackageExists($this->conveyor->vendor(), $this->conveyor->package());
$this->makeProgress();

// Create the package directory
$this->info('Creating packages directory...');
$this->conveyor->makeDir($this->conveyor->packagesPath());
$this->fileHandler->makeDir($this->fileHandler->packagesPath());

// Clone the repository
$this->info('Cloning repository...');
exec("git clone -q $source ".$this->conveyor->packagePath(), $output, $exit_code);
exec("git clone -q $source ".$this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()), $output, $exit_code);

if ($exit_code !== 0) {
$this->error('Unable to clone repository');
Expand All @@ -83,7 +87,7 @@ public function handle(): void

// Create the vendor directory
$this->info('Creating vendor...');
$this->conveyor->makeDir($this->conveyor->vendorPath());
$this->fileHandler->makeDir($this->fileHandler->vendorPath($this->conveyor->vendor()));
$this->makeProgress();

$this->info('Installing package...');
Expand Down
25 changes: 17 additions & 8 deletions src/Commands/NewPackage.php
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Contracts\Validation\Validator as ValidatorInterface;
use Illuminate\Support\Facades\Validator;
use JeroenG\Packager\Conveyor;
use JeroenG\Packager\FileHandlerInterface;
use JeroenG\Packager\ProgressBar;
use JeroenG\Packager\ValidationRules\ValidClassName;
use JeroenG\Packager\Wrapping;
Expand Down Expand Up @@ -35,11 +36,14 @@ class NewPackage extends Command
*/
protected Wrapping $wrapping;

public function __construct(Conveyor $conveyor, Wrapping $wrapping)
protected FileHandlerInterface $fileHandler;

public function __construct(Conveyor $conveyor, Wrapping $wrapping, FileHandlerInterface $fileHandler)
{
parent::__construct();
$this->conveyor = $conveyor;
$this->wrapping = $wrapping;
$this->fileHandler = $fileHandler;
}

public function handle(): int
Expand Down Expand Up @@ -74,17 +78,17 @@ public function handle(): int

// Start creating the package
$this->info('Creating package '.$this->conveyor->vendor().'\\'.$this->conveyor->package().'...');
$this->conveyor->checkIfPackageExists();
$this->fileHandler->checkIfPackageExists($this->conveyor->vendor(), $this->conveyor->package());
$this->makeProgress();

// Create the package directory
$this->info('Creating packages directory...');
$this->conveyor->makeDir($this->conveyor->packagesPath());
$this->fileHandler->makeDir($this->fileHandler->packagesPath());
$this->makeProgress();

// Create the vendor directory
$this->info('Creating vendor...');
$this->conveyor->makeDir($this->conveyor->vendorPath());
$this->fileHandler->makeDir($this->fileHandler->vendorPath($this->conveyor->vendor()));
$this->makeProgress();

// Get the packager package skeleton
Expand All @@ -94,8 +98,13 @@ public function handle(): int
} else {
$this->conveyor->downloadSkeleton($this->option('skeleton'));
}
$manifest = (file_exists($this->conveyor->packagePath().'/rewriteRules.php')) ? $this->conveyor->packagePath().'/rewriteRules.php' : null;
$this->conveyor->renameFiles();
$manifest = (file_exists($this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()).'/rewriteRules.php')) ? $this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()).'/rewriteRules.php' : null;
$this->fileHandler->renameFiles(
$this->conveyor->vendorStudly(),
$this->conveyor->packageStudly(),
$this->conveyor->vendor(),
$this->conveyor->package(),
);
$this->makeProgress();

// Replacing skeleton placeholders
Expand Down Expand Up @@ -133,11 +142,11 @@ public function handle(): int
}

// Fill all placeholders in all files with the replacements.
$this->wrapping->fill($this->conveyor->packagePath());
$this->wrapping->fill($this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()));

// Make sure to remove the rule files to avoid clutter.
if ($manifest !== null) {
$this->conveyor->cleanUpRules();
$this->fileHandler->cleanUpRules($this->conveyor->vendor(), $this->conveyor->package());
}

$this->makeProgress();
Expand Down
14 changes: 9 additions & 5 deletions src/Commands/PublishPackage.php
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Console\Command;
use JeroenG\Packager\Conveyor;
use JeroenG\Packager\FileHandlerInterface;
use JeroenG\Packager\ProgressBar;

/**
Expand All @@ -29,10 +30,13 @@ class PublishPackage extends Command
*/
protected Conveyor $conveyor;

public function __construct(Conveyor $conveyor)
protected FileHandlerInterface $fileHandler;

public function __construct(Conveyor $conveyor, FileHandlerInterface $fileHandler)
{
parent::__construct();
$this->conveyor = $conveyor;
$this->fileHandler = $fileHandler;
}

public function handle(): void
Expand All @@ -45,17 +49,17 @@ public function handle(): void
$this->conveyor->package($this->argument('name'));

$this->info('Initialising Git if not already done so...');
if (! file_exists($this->conveyor->packagePath().'/.git/')) {
exec('cd '.$this->conveyor->packagePath().' && git init && git add --all && git commit -m "Initial commit"');
if (! file_exists($this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()).'/.git/')) {
exec('cd '.$this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()).' && git init && git add --all && git commit -m "Initial commit"');
}
$this->makeProgress();

$this->info('Git is set up, adding the remote repository...');
exec('cd '.$this->conveyor->packagePath().' && git remote add origin '.$this->argument('url'));
exec('cd '.$this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()).' && git remote add origin '.$this->argument('url'));
$this->makeProgress();

$this->info('Pushing to Github...');
exec('cd '.$this->conveyor->packagePath().' && git push -u origin master');
exec('cd '.$this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()).' && git push -u origin master');
$this->makeProgress();

// Finished publishing the package, end of the progress bar
Expand Down

0 comments on commit ac44bb6

Please sign in to comment.