Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code grooming #335

Merged
merged 6 commits into from Mar 20, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,8 @@
* Add a way to merge an application `box.json` config file used by `castor:repack`command
* Deprecate `Context::withPath()` in favor of `Context::withWorkingDirectory()`
* Deprecate `path` argument in `capture()`, `exit_code()`, `run()`, `with()` in favor of `workingDirectory`
* Deprecate `Castor\TaskDescriptorCollection` in favor of
`Castor\Descriptor\TaskDescriptorCollection`

## 0.14.0 (2024-03-08)

Expand Down
4 changes: 2 additions & 2 deletions bin/generate-tests.php
Expand Up @@ -4,7 +4,7 @@
require __DIR__ . '/../vendor/autoload.php';

use Castor\Console\ApplicationFactory;
use Castor\PlatformUtil;
use Castor\PlatformHelper;
use Castor\Tests\Helper\OutputCleaner;
use Castor\Tests\Helper\WebServerHelper;
use Symfony\Component\Console\Input\ArrayInput;
Expand All @@ -19,7 +19,7 @@
WebServerHelper::start();

$fs = new Filesystem();
$fs->remove(PlatformUtil::getCacheDirectory());
$fs->remove(PlatformHelper::getCacheDirectory());
$fs->remove(__DIR__ . '/../tests/Examples/Generated');
$fs->mkdir(__DIR__ . '/../tests/Examples/Generated');

Expand Down
20 changes: 10 additions & 10 deletions src/Console/Application.php
Expand Up @@ -4,23 +4,23 @@

use Castor\Console\Command\SymfonyTaskCommand;
use Castor\Console\Command\TaskCommand;
use Castor\Console\Output\SectionOutput;
use Castor\Console\Output\VerbosityLevel;
use Castor\Context;
use Castor\ContextDescriptor;
use Castor\ContextGeneratorDescriptor;
use Castor\ContextRegistry;
use Castor\Descriptor\ContextDescriptor;
use Castor\Descriptor\ContextGeneratorDescriptor;
use Castor\Descriptor\ListenerDescriptor;
use Castor\Descriptor\SymfonyTaskDescriptor;
use Castor\Descriptor\TaskDescriptor;
use Castor\Descriptor\TaskDescriptorCollection;
use Castor\Event\AfterApplicationInitializationEvent;
use Castor\EventDispatcher;
use Castor\ExpressionLanguage;
use Castor\Fingerprint\FingerprintHelper;
use Castor\FunctionFinder;
use Castor\GlobalHelper;
use Castor\ListenerDescriptor;
use Castor\PlatformUtil;
use Castor\SectionOutput;
use Castor\SymfonyTaskDescriptor;
use Castor\TaskDescriptor;
use Castor\TaskDescriptorCollection;
use Castor\VerbosityLevel;
use Castor\PlatformHelper;
use Castor\WaitForHelper;
use Monolog\Logger;
use Psr\Cache\CacheItemPoolInterface;
Expand Down Expand Up @@ -203,7 +203,7 @@ private function initializeApplication(InputInterface $input): TaskDescriptorCol
$contextNames = $this->contextRegistry->getNames();

if ($contextNames) {
$defaultContext = PlatformUtil::getEnv('CASTOR_CONTEXT') ?: $this->contextRegistry->getDefaultName();
$defaultContext = PlatformHelper::getEnv('CASTOR_CONTEXT') ?: $this->contextRegistry->getDefaultName();

$this->getDefinition()->addOption(new InputOption(
'context',
Expand Down
4 changes: 2 additions & 2 deletions src/Console/ApplicationFactory.php
Expand Up @@ -14,7 +14,7 @@
use Castor\Listener\UpdateCastorListener;
use Castor\Monolog\Processor\ProcessProcessor;
use Castor\PathHelper;
use Castor\PlatformUtil;
use Castor\PlatformHelper;
use Castor\Stub\StubsGenerator;
use Castor\WaitForHelper;
use Monolog\Logger;
Expand Down Expand Up @@ -45,7 +45,7 @@ public static function create(): SymfonyApplication
'User-Agent' => 'Castor/' . Application::VERSION,
],
]);
$cacheDir = PlatformUtil::getCacheDirectory();
$cacheDir = PlatformHelper::getCacheDirectory();
$cache = new FilesystemAdapter(directory: $cacheDir);
$logger = new Logger('castor', [], [new ProcessProcessor()]);
$fs = new Filesystem();
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/CompileCommand.php
Expand Up @@ -3,7 +3,7 @@
namespace Castor\Console\Command;

use Castor\PathHelper;
use Castor\PlatformUtil;
use Castor\PlatformHelper;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$phpBuildCacheKey = $this->generatePHPBuildCacheKey($input);

$spcBinaryPath = PlatformUtil::getCacheDirectory() . '/castor-php-static-compiler/' . $phpBuildCacheKey . '/spc';
$spcBinaryPath = PlatformHelper::getCacheDirectory() . '/castor-php-static-compiler/' . $phpBuildCacheKey . '/spc';
$spcBinaryDir = \dirname($spcBinaryPath);

$this->setupSPC(
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Castor;
namespace Castor\Console\Output;

use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Castor;
namespace Castor\Console\Output;

use Symfony\Component\Console\Output\OutputInterface;

Expand Down
2 changes: 2 additions & 0 deletions src/Context.php
Expand Up @@ -2,6 +2,8 @@

namespace Castor;

use Castor\Console\Output\VerbosityLevel;

class Context implements \ArrayAccess
{
public readonly string $workingDirectory;
Expand Down
1 change: 1 addition & 0 deletions src/ContextRegistry.php
Expand Up @@ -2,6 +2,7 @@

namespace Castor;

use Castor\Descriptor\ContextDescriptor;
use Castor\Exception\FunctionConfigurationException;

/** @internal */
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Castor;
namespace Castor\Descriptor;

use Castor\Attribute\AsContext;

Expand Down
@@ -1,8 +1,9 @@
<?php

namespace Castor;
namespace Castor\Descriptor;

use Castor\Attribute\AsContextGenerator;
use Castor\Context;

/** @internal */
class ContextGeneratorDescriptor
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Castor;
namespace Castor\Descriptor;

use Castor\Attribute\AsListener;

Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Castor;
namespace Castor\Descriptor;

use Castor\Attribute\AsSymfonyTask;

Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Castor;
namespace Castor\Descriptor;

use Castor\Attribute\AsTask;

Expand Down
16 changes: 16 additions & 0 deletions src/Descriptor/TaskDescriptorCollection.php
@@ -0,0 +1,16 @@
<?php

namespace Castor\Descriptor;

class TaskDescriptorCollection
{
/**
* @param TaskDescriptor[] $taskDescriptors
* @param SymfonyTaskDescriptor[] $symfonyTaskDescriptors
*/
public function __construct(
public readonly array $taskDescriptors,
public readonly array $symfonyTaskDescriptors,
) {
}
}
2 changes: 1 addition & 1 deletion src/Event/AfterApplicationInitializationEvent.php
Expand Up @@ -3,7 +3,7 @@
namespace Castor\Event;

use Castor\Console\Application;
use Castor\TaskDescriptorCollection;
use Castor\Descriptor\TaskDescriptorCollection;

class AfterApplicationInitializationEvent
{
Expand Down
1 change: 1 addition & 0 deletions src/Fingerprint/FingerprintHelper.php
Expand Up @@ -5,6 +5,7 @@
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Contracts\Cache\CacheInterface;

/** @internal */
class FingerprintHelper
{
private const SUFFIX = '.fingerprint';
Expand Down
5 changes: 5 additions & 0 deletions src/FunctionFinder.php
Expand Up @@ -7,6 +7,11 @@
use Castor\Attribute\AsListener;
use Castor\Attribute\AsSymfonyTask;
use Castor\Attribute\AsTask;
use Castor\Descriptor\ContextDescriptor;
use Castor\Descriptor\ContextGeneratorDescriptor;
use Castor\Descriptor\ListenerDescriptor;
use Castor\Descriptor\SymfonyTaskDescriptor;
use Castor\Descriptor\TaskDescriptor;
use Castor\Exception\FunctionConfigurationException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Finder\Finder;
Expand Down
1 change: 1 addition & 0 deletions src/GlobalHelper.php
Expand Up @@ -3,6 +3,7 @@
namespace Castor;

use Castor\Console\Application;
use Castor\Console\Output\SectionOutput;
use Monolog\Logger;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Console\Command\Command;
Expand Down
4 changes: 2 additions & 2 deletions src/Listener/UpdateCastorListener.php
Expand Up @@ -3,7 +3,7 @@
namespace Castor\Listener;

use Castor\Console\Application;
use Castor\PlatformUtil;
use Castor\PlatformHelper;
use JoliCode\PhpOsHelper\OsHelper;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -33,7 +33,7 @@ public function checkUpdate(ConsoleCommandEvent $event): void
if (class_exists(\RepackedApplication::class)) {
return;
}
if (PlatformUtil::getEnv('DISABLE_VERSION_CHECK')) {
if (PlatformHelper::getEnv('DISABLE_VERSION_CHECK')) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/PlatformUtil.php → src/PlatformHelper.php
Expand Up @@ -9,7 +9,7 @@
*
* @internal
*/
final class PlatformUtil
final class PlatformHelper
{
/**
* getenv() equivalent but reads from the runtime global variables first.
Expand Down
18 changes: 8 additions & 10 deletions src/TaskDescriptorCollection.php
Expand Up @@ -2,15 +2,13 @@

namespace Castor;

class TaskDescriptorCollection
use Castor\Descriptor\TaskDescriptorCollection as BaseTaskDescriptorCollection;

trigger_deprecation('castor', '0.15.0', 'The "%s" class is deprecated, use "%s" instead.', TaskDescriptorCollection::class, BaseTaskDescriptorCollection::class);

/**
* @deprecated since Castor 0.15.0, use Castor\Descriptor\TaskDescriptorCollection instead
*/
class TaskDescriptorCollection extends BaseTaskDescriptorCollection
{
/**
* @param TaskDescriptor[] $taskDescriptors
* @param SymfonyTaskDescriptor[] $symfonyTaskDescriptors
*/
public function __construct(
public readonly array $taskDescriptors,
public readonly array $symfonyTaskDescriptors,
) {
}
}
8 changes: 4 additions & 4 deletions tests/Examples/Fingerprint/FingerprintedTestCase.php
Expand Up @@ -2,7 +2,7 @@

namespace Castor\Tests\Examples\Fingerprint;

use Castor\PlatformUtil;
use Castor\PlatformHelper;
use Castor\Tests\TaskTestCase;
use Symfony\Component\Finder\Finder;

Expand All @@ -20,10 +20,10 @@ protected function setUp(): void

private static function clearFingerprintsCache(): void
{
if (is_dir(PlatformUtil::getCacheDirectory())) {
if (is_dir(PlatformHelper::getCacheDirectory())) {
foreach (
(new Finder())
->in(PlatformUtil::getCacheDirectory())
->in(PlatformHelper::getCacheDirectory())
->contains('.fingerprint')
->files() as $file
) {
Expand All @@ -32,7 +32,7 @@ private static function clearFingerprintsCache(): void

foreach (
(new Finder())
->in(PlatformUtil::getCacheDirectory())
->in(PlatformHelper::getCacheDirectory())
->notContains('.fingerprint')
->directories() as $directory
) {
Expand Down
@@ -1,5 +1,5 @@

In FunctionFinder.php line 218:
In FunctionFinder.php line 223:

Function "gen()" is not properly configured:
The context generator "foo" must not have arguments.
Expand Down
@@ -1,5 +1,5 @@

In FunctionFinder.php line 209:
In FunctionFinder.php line 214:

Function "gen()" is not properly configured:
The contexts generator must not have arguments.
Expand Down
@@ -1,5 +1,5 @@

In FunctionFinder.php line 214:
In FunctionFinder.php line 219:

Function "gen()" is not properly configured:
The context generator "foo" is not callable.
Expand Down
4 changes: 2 additions & 2 deletions tests/bin/compile-get-cache-key
Expand Up @@ -4,7 +4,7 @@
require __DIR__ . '/../../vendor/autoload.php';

use Castor\Console\Command\CompileCommand;
use Castor\PlatformUtil;
use Castor\PlatformHelper;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;

Expand All @@ -14,7 +14,7 @@ $command = (new class() extends CompileCommand {
}}
)
->setCode(Closure::bind(
fn($input) => (print PlatformUtil::getCacheDirectory() . '/castor-php-static-compiler/' . $this->generatePHPBuildCacheKey($input)) && 0,
fn($input) => (print PlatformHelper::getCacheDirectory() . '/castor-php-static-compiler/' . $this->generatePHPBuildCacheKey($input)) && 0,
null,
CompileCommand::class
))
Expand Down