Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ jobs:
name: 'Check Active Classes'
run: vendor/bin/class-leak check bin src tests --ansi

-
name: 'Run "Compare Projects" command'
run: php bin/monitor compare-projects tests/project-fixture/first-project --merge-project tests/project-fixture/second-project --ansi

-
name: 'Composer dependency Analyser'
run: vendor/bin/composer-dependency-analyser
Expand All @@ -48,7 +52,7 @@ jobs:
# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
coverage: none

# composer install cache - https://github.com/ramsey/composer-install
Expand Down
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The MIT License
---------------

Copyright (c) 2020 Tomas Votruba (https://tomasvotruba.com)
Copyright (c) 2025 Tomas Votruba (https://tomasvotruba.com)

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand All @@ -22,4 +22,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
OTHER DEALINGS IN THE SOFTWARE.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ composer require rector/monitor --dev
### 1. Quality control for `composer.json` in multiple repositories

```bash
vendor/bin/monitor quality-control
vendor/bin/monitor analyze
```


```bash
vendor/bin/monitor quality-control --clear-cache
vendor/bin/monitor analyze --clear-cache
```


<br>

### 2. See full Matrix of repositories's dependencies
Expand Down
6 changes: 1 addition & 5 deletions bin/monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Rector\Monitor\DependencyInjection\ContainerFactory;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;

$scoperAutoloadFilepath = __DIR__ . '/../vendor/scoper-autoload.php';
if (file_exists($scoperAutoloadFilepath)) {
Expand Down Expand Up @@ -33,6 +31,4 @@
$container = $containerFactory->create();

$application = $container->make(Application::class);

$exitCode = $application->run(new ArgvInput(), new ConsoleOutput());
exit($exitCode);
exit($application->run());
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bin/monitor"
],
"require": {
"php": ">=8.2",
"php": ">=8.3",
"composer/semver": "^3.4",
"illuminate/container": "12.40.*",
"nette/neon": "^3.4",
Expand Down
18 changes: 11 additions & 7 deletions monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
use Rector\Monitor\Config\MonitorConfig;

return MonitorConfig::configure()
->addRepositories(['git@bitbucket.org:arestravelinc/lib-client.git'])
->addRepositoryBranch('git@bitbucket.org:arestravelinc/legacy-appserver-service.git', 'stage')
->addRepositoryBranch('git@bitbucket.org:arestravelinc/be5.git', 'stage')
->addRepositoryBranch('git@bitbucket.org:arestravelinc/ares-admin.git', 'stage')
->addRepositoryBranch('git@bitbucket.org:arestravelinc/content-service.git', 'stage')
->addRepositoryBranch('git@bitbucket.org:arestravelinc/payment-service.git', 'stage')
->addRepositories([
// rector repositories
'https://github.com/rectorphp/rector-src',
'https://github.com/rectorphp/rector-symfony',
'https://github.com/rectorphp/rector-doctrine',
'https://github.com/rectorphp/rector-phpunit',
'https://github.com/rectorphp/rector-downgrade-php',
])
// ->addRepositoryBranch('...', 'stage')

// composer rules
->disallowPackages(['symfony/phpunit-bridge'])
// ->disallowPackages(['symfony/phpunit-bridge'])
->requirePackages([
'phpstan/phpstan',
'phpecs/phpecs',
'rector/rector',
'phpstan/phpstan-deprecation-rules',
'phpstan/extension-installer',
'symplify/phpstan-rules',
])

// version requirements
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
includes:
- vendor/symplify/phpstan-rules/config/code-complexity-rules.neon
- vendor/symplify/phpstan-rules/config/configurable-rules.neon
- vendor/symplify/phpstan-rules/config/naming-rules.neon
- vendor/symplify/phpstan-rules/config/static-rules.neon

parameters:
level: 8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

declare(strict_types=1);

namespace Rector\Monitor\Command;

namespace Rector\Monitor\Analyze\Command;

use Rector\Monitor\Analyze\Contract\RuleProcessorInterface;
use Rector\Monitor\Analyze\Reporting\ErrorCollector;
use Rector\Monitor\Analyze\RuleProcessor\DisallowedPackagesRuleProcessor;
use Rector\Monitor\Analyze\RuleProcessor\MetafileProcessor\NoPHPStanBaselineMetafileProcessor;
use Rector\Monitor\Analyze\RuleProcessor\MissingPackagesRuleProcessor;
use Rector\Monitor\Analyze\RuleProcessor\TooLowPackagesRulesProcessor;
use Rector\Monitor\Config\ConfigInitializer;
use Rector\Monitor\Config\MonitorConfigProvider;
use Rector\Monitor\Configuration\ConfigInitializer;
use Rector\Monitor\Contract\RuleProcessorInterface;
use Rector\Monitor\Git\RepositoryMetafilesResolver;
use Rector\Monitor\Reporting\ErrorCollector;
use Rector\Monitor\RuleProcessor\DisallowedPackagesRuleProcessor;
use Rector\Monitor\RuleProcessor\MetafileProcessor\NoPHPStanBaselineMetafileProcessor;
use Rector\Monitor\RuleProcessor\MissingPackagesRuleProcessor;
use Rector\Monitor\RuleProcessor\TooLowPackagesRulesProcessor;
use Rector\Monitor\ValueObject\RepositoryCollection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -51,7 +51,7 @@ protected function configure(): void
$this->setAliases(['analyse']);

$this->setDescription(
'Check repositoryCollection composer.json files, assess "require" section, root files, tooling setup and min PHP version with defined quality control rules'
'Check repositories composer.json files, assess "require" section, root files, tooling setup and min PHP version with defined quality control rules'
);

$this->addOption(
Expand Down Expand Up @@ -117,7 +117,7 @@ private function printAnalysisSummary(RepositoryCollection $repositoryCollection
$this->symfonyStyle->writeln(sprintf(
' Summary: %d %s analyzed, %d with issues',
$repositoryCollection->count(),
$repositoryCollection->count() === 1 ? 'repository' : 'repositoryCollection',
$repositoryCollection->count() === 1 ? 'repository' : 'repositories',
$erroredRepositoryCount
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace Rector\Monitor\Contract;
namespace Rector\Monitor\Analyze\Contract;

use Rector\Monitor\Analyze\Reporting\ErrorCollector;
use Rector\Monitor\Config\MonitorConfig;
use Rector\Monitor\Reporting\ErrorCollector;
use Rector\Monitor\ValueObject\ComposerJson;

interface RuleProcessorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rector\Monitor\Reporting;
namespace Rector\Monitor\Analyze\Reporting;

final class ErrorCollector
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Rector\Monitor\RuleProcessor;
namespace Rector\Monitor\Analyze\RuleProcessor;

use Rector\Monitor\Analyze\Contract\RuleProcessorInterface;
use Rector\Monitor\Analyze\Reporting\ErrorCollector;
use Rector\Monitor\Config\MonitorConfig;
use Rector\Monitor\Contract\RuleProcessorInterface;
use Rector\Monitor\Reporting\ErrorCollector;
use Rector\Monitor\ValueObject\ComposerJson;

final class DisallowedPackagesRuleProcessor implements RuleProcessorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Rector\Monitor\RuleProcessor\MetafileProcessor;
namespace Rector\Monitor\Analyze\RuleProcessor\MetafileProcessor;

use Rector\Monitor\Analyze\Contract\RuleProcessorInterface;
use Rector\Monitor\Analyze\Reporting\ErrorCollector;
use Rector\Monitor\Config\MonitorConfig;
use Rector\Monitor\Contract\RuleProcessorInterface;
use Rector\Monitor\Reporting\ErrorCollector;
use Rector\Monitor\ValueObject\ComposerJson;

final readonly class NoPHPStanBaselineMetafileProcessor implements RuleProcessorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Rector\Monitor\RuleProcessor;
namespace Rector\Monitor\Analyze\RuleProcessor;

use Rector\Monitor\Analyze\Contract\RuleProcessorInterface;
use Rector\Monitor\Analyze\Reporting\ErrorCollector;
use Rector\Monitor\Config\MonitorConfig;
use Rector\Monitor\Contract\RuleProcessorInterface;
use Rector\Monitor\Reporting\ErrorCollector;
use Rector\Monitor\ValueObject\ComposerJson;

final class MissingPackagesRuleProcessor implements RuleProcessorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace Rector\Monitor\RuleProcessor;
namespace Rector\Monitor\Analyze\RuleProcessor;

use Composer\Semver\Semver;
use Rector\Monitor\Analyze\Contract\RuleProcessorInterface;
use Rector\Monitor\Analyze\Reporting\ErrorCollector;
use Rector\Monitor\Config\MonitorConfig;
use Rector\Monitor\Contract\RuleProcessorInterface;
use Rector\Monitor\Reporting\ErrorCollector;
use Rector\Monitor\ValueObject\ComposerJson;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace Rector\Monitor\Configuration;
namespace Rector\Monitor\Config;

use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;

final class ConfigInitializer
final readonly class ConfigInitializer
{
public function __construct(
private SymfonyStyle $symfonyStyle,
Expand Down
6 changes: 5 additions & 1 deletion src/Config/MonitorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ public function addRepositories(array $repositories): self
Assert::allString($repositories);

foreach ($repositories as $repository) {
if (! str_ends_with($repository, '.git')) {
$repository .= '.git';
}

MonitorAssert::assertRepositoryUrl($repository);
$repositories[] = $repository;
$this->repositories[] = $repository;
}

return $this;
Expand Down
2 changes: 2 additions & 0 deletions src/Console/Command/CleanListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Monitor\Console\Command;

use Override;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Command\ListCommand;
Expand All @@ -17,6 +18,7 @@
*/
final class CleanListCommand extends ListCommand
{
#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
Assert::isInstanceOf($this->getApplication(), Application::class);
Expand Down
2 changes: 2 additions & 0 deletions src/Console/MonitorConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Monitor\Console;

use Override;
use Rector\Monitor\Console\Command\CleanListCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\CompleteCommand;
Expand All @@ -12,6 +13,7 @@

final class MonitorConsoleApplication extends Application
{
#[Override]
protected function getDefaultCommands(): array
{
return [
Expand Down
30 changes: 4 additions & 26 deletions src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
namespace Rector\Monitor\DependencyInjection;

use Illuminate\Container\Container;
use Rector\Monitor\Analyze\Command\AnalyzeCommand;
use Rector\Monitor\Console\MonitorConsoleApplication;
use Rector\Monitor\Macro\Command\CompareProjectsCommand;
use Rector\Monitor\Matrix\Command\MatrixCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;
use Webmozart\Assert\Assert;

final class ContainerFactory
{
Expand All @@ -26,7 +27,7 @@ public function create(): Container
$container->singleton(Application::class, function (Container $container): MonitorConsoleApplication {
$monitorConsoleApplication = new MonitorConsoleApplication('Rector Monitor');

$commandClasses = $this->findCommandClasses();
$commandClasses = [AnalyzeCommand::class, MatrixCommand::class, CompareProjectsCommand::class];

// register commands
foreach ($commandClasses as $commandClass) {
Expand Down Expand Up @@ -57,27 +58,4 @@ public function hideDefaultCommands(Application $application): void
$application->get('help')
->setHidden(true);
}

/**
* @return string[]
*/
private function findCommandClasses(): array
{
$commandFinder = Finder::create()
->files()
->name('*Command.php')
->in(__DIR__ . '/../Command');

$commandClasses = [];
foreach ($commandFinder as $commandFile) {
$commandClass = 'Rector\\Monitor\\Command\\' . $commandFile->getBasename('.php');

// make sure it exists
Assert::classExists($commandClass);

$commandClasses[] = $commandClass;
}

return $commandClasses;
}
}
4 changes: 3 additions & 1 deletion src/Git/RepositoryMetafilesResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public function __construct(
public function decorateRepositories(RepositoryCollection $repositoryCollection, bool $clearCache = false): void
{
foreach ($repositoryCollection->all() as $repository) {
$repositoryCacheDirectory = getcwd() . '/monitor-cache/repository-' . md5($repository->getRepositoryUrl());
$repositoryCacheDirectory = sys_get_temp_dir() . '/rector-monitor-cache/repository-' . md5(
$repository->getRepositoryUrl()
);

if (file_exists($repositoryCacheDirectory) && $this->hasDirectorySomeFiles($repositoryCacheDirectory)) {
if ($clearCache) {
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/SymfonyColumnStyler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class SymfonyColumnStyler
public static function styleHighsAndLows(array $tableRow): array
{
// set highs and lows
$stringValues = array_filter($tableRow, 'is_string');
$stringValues = array_filter($tableRow, is_string(...));
$stringValues = array_unique($stringValues);

if (count($stringValues) < 2) {
Expand Down
Loading