Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 17, 2023
1 parent a64431b commit 7e81a29
Show file tree
Hide file tree
Showing 20 changed files with 173 additions and 177 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ composer.lock
/vendor

.phpunit.result.cache


bootstrap/cache/*
!bootstrap/cache/.gitkeep

storage/*
15 changes: 15 additions & 0 deletions app/Console/ClassLeakKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace TomasVotruba\ClassLeak\Console;

use Illuminate\Foundation\Console\Kernel;

final class ClassLeakKernel extends Kernel
{
protected function commands(): void
{
$this->load(__DIR__ . '/Commands');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TomasVotruba\ClassLeak\Command;
namespace TomasVotruba\ClassLeak\Console\Commands;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -16,7 +16,7 @@
use TomasVotruba\ClassLeak\UseImportsResolver;
use TomasVotruba\ClassLeak\ValueObject\Option;

final class CheckActiveClassCommand extends Command
final class CheckCommand extends Command
{
public function __construct(
private readonly ClassNamesFinder $classNamesFinder,
Expand All @@ -31,7 +31,8 @@ public function __construct(

protected function configure(): void
{
$this->setName('check-active-class');
$this->setName('check');

$this->setDescription('Check classes that are not used in any config and in the code');

$this->addArgument(
Expand Down
20 changes: 0 additions & 20 deletions app/Console/EasyCIApplication.php

This file was deleted.

27 changes: 2 additions & 25 deletions app/Finder/PhpFilesFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,17 @@

namespace TomasVotruba\ClassLeak\Finder;

use SplFileInfo;
use Symfony\Component\Console\Input\InputInterface;
use Symplify\PackageBuilder\Parameter\ParameterProvider;
use Symplify\SmartFileSystem\Finder\SmartFinder;
use TomasVotruba\ClassLeak\ValueObject\Option;
use Webmozart\Assert\Assert;

final class PhpFilesFinder
{
public function __construct(
private readonly SmartFinder $smartFinder,
private readonly ParameterProvider $parameterProvider
) {
}

/**
* @return string[]
*/
public function findPhpFiles(InputInterface $input): array
public function findPhpFiles(array $paths): array
{
$excludedCheckPaths = $this->parameterProvider->provideArrayParameter(Option::EXCLUDED_CHECK_PATHS);

$paths = (array) $input->getArgument(Option::SOURCES);

// fallback to config paths
if ($paths === []) {
$paths = $this->parameterProvider->provideArrayParameter(Option::PATHS);
$paths = [getcwd()];
}

$fileInfos = $this->smartFinder->find($paths, '*.php', $excludedCheckPaths);

$filePaths = array_map(static fn (SplFileInfo $fileInfo): string => $fileInfo->getRealPath(), $fileInfos);

Assert::allString($filePaths);
return $filePaths;
}
}
30 changes: 0 additions & 30 deletions app/Finder/ProjectFilesFinder.php

This file was deleted.

21 changes: 0 additions & 21 deletions app/Kernel/EasyCIKernel.php

This file was deleted.

33 changes: 33 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace TomasVotruba\ClassLeak\Providers;

use Illuminate\Support\ServiceProvider;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Style\SymfonyStyle;

final class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(Parser::class, function (): Parser {
$parserFactory = new ParserFactory();
return $parserFactory->create(ParserFactory::PREFER_PHP7);
});

$this->app->singleton(
SymfonyStyle::class,
static function (): SymfonyStyle {
// use null output ofr tests to avoid printing
$consoleOutput = defined('PHPUNIT_COMPOSER_INSTALL') ? new NullOutput() : new ConsoleOutput();
return new SymfonyStyle(new ArrayInput([]), $consoleOutput);
}
);
}
}
17 changes: 0 additions & 17 deletions app/ValueObject/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,9 @@ final class Option
*/
public const SOURCES = 'sources';

/**
* @var string
*/
public const LINE_LIMIT = 'line-limit';

/**
* @deprecated Use EasyCIConfig instead
* @var string
*/
public const TYPES_TO_SKIP = 'types_to_skip';

/**
* @deprecated Use EasyCIConfig instead
* @var string
*/
public const EXCLUDED_CHECK_PATHS = 'excluded_check_paths';

/**
* @deprecated Use EasyCIConfig instead
* @var string
*/
public const PATHS = 'paths';
}
34 changes: 13 additions & 21 deletions bin/class-leak.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,20 @@

declare(strict_types=1);

use TomasVotruba\ClassLeak\Kernel\EasyCIKernel;
use Illuminate\Contracts\Console\Kernel;

$possibleAutoloadPaths = [
// dependency
__DIR__ . '/../../../autoload.php',
// after split package
__DIR__ . '/../vendor/autoload.php',
// monorepo
__DIR__ . '/../../../vendor/autoload.php',
];
require_once __DIR__ . '/../vendor/autoload.php';

foreach ($possibleAutoloadPaths as $possibleAutoloadPath) {
if (file_exists($possibleAutoloadPath)) {
require_once $possibleAutoloadPath;
break;
}
}
/** @var \Illuminate\Foundation\Application $application */
$application = require_once __DIR__ . '/../bootstrap/app.php';

$scoperAutoloadFilepath = __DIR__ . '/../vendor/scoper-autoload.php';
if (file_exists($scoperAutoloadFilepath)) {
require_once $scoperAutoloadFilepath;
}
/** @var Kernel $kernel */
$kernel = $application->make(Kernel::class);

$kernelBootAndApplicationRun = new KernelBootAndApplicationRun(EasyCIKernel::class);
$kernelBootAndApplicationRun->run();
$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput(),
new Symfony\Component\Console\Output\ConsoleOutput()
);

$kernel->terminate($input, $status);
exit($status);
15 changes: 15 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Illuminate\Foundation\Application;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Foundation\Exceptions\Handler;
use TomasVotruba\ClassLeak\Console\ClassLeakKernel;

$application = new Application($_ENV['APP_BASE_PATH'] ?? dirname(__DIR__));

$application->singleton(\Illuminate\Contracts\Console\Kernel::class, ClassLeakKernel::class);
$application->singleton(ExceptionHandler::class, Handler::class);

return $application;
1 change: 1 addition & 0 deletions bootstrap/cache/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
keep
22 changes: 7 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@
],
"require": {
"php": ">=8.1",
"nette/robot-loader": "^3.4",
"illuminate/console": "^10.15",
"illuminate/container": "^10.15",
"nette/utils": "^3.2",
"nikic/php-parser": "^4.16",
"symfony/console": "^6.2",
"symfony/dependency-injection": "6.1.*",
"symplify/package-builder": "^11.2",
"symfony/console": "^6.3",
"tomasvotruba/punchcard": "^0.2.7"
},
"require-dev": {
"cweagans/composer-patches": "^1.7",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan": "^1.10.25",
"phpunit/phpunit": "^10.2",
"laravel/framework": "^10.13",
"rector/rector": "*",
"symplify/easy-coding-standard": "^11.2",
"symplify/phpstan-extensions": "^11.1",
"symplify/easy-coding-standard": "^11.5",
"symplify/phpstan-extensions": "^11.2",
"tomasvotruba/cognitive-complexity": "^0.1",
"tomasvotruba/type-coverage": "^0.2",
"tomasvotruba/unused-public": "^0.1"
Expand All @@ -38,17 +37,10 @@
"TomasVotruba\\ClassLeak\\Tests\\": "tests"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-intl-grapheme": "*",
"symfony/polyfill-intl-normalizer": "*",
"symfony/polyfill-mbstring": "*"
},
"config": {
"sort-packages": true,
"platform-check": false,
"allow-plugins": {
"cweagans/composer-patches": true,
"phpstan/extension-installer": true
}
},
Expand Down
9 changes: 9 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

use TomasVotruba\PunchCard\AppConfig;

return AppConfig::make()
->providers([\TomasVotruba\ClassLeak\Providers\AppServiceProvider::class])
->toArray();
8 changes: 8 additions & 0 deletions config/cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

use TomasVotruba\PunchCard\CacheConfig;

return CacheConfig::make()
->toArray();
8 changes: 8 additions & 0 deletions config/logging.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

use TomasVotruba\PunchCard\LoggingConfig;

return LoggingConfig::make()
->toArray();
18 changes: 0 additions & 18 deletions easy-ci.php

This file was deleted.

Loading

0 comments on commit 7e81a29

Please sign in to comment.