Skip to content

Commit

Permalink
Maintenance on CodeBase (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes authored Sep 10, 2024
1 parent 71c09b4 commit 4ad8b79
Show file tree
Hide file tree
Showing 133 changed files with 435 additions and 224 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ To get the diff between two versions, go to https://github.com/SonsOfPHP/sonsofp

## [Unreleased]

* [PR #225](https://github.com/SonsOfPHP/sonsofphp/pull/225) Maintenance
* [PR #222](https://github.com/SonsOfPHP/sonsofphp/pull/222) [Assert] New Component
* [PR #221](https://github.com/SonsOfPHP/sonsofphp/pull/221) [StateMachine] New Contract and Component
* [PR #220](https://github.com/SonsOfPHP/sonsofphp/pull/220) [Filesystem] Adds bridges for AWS and LiipImagineBundle
Expand Down
24 changes: 21 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use Rector\Php82\Rector\FuncCall\Utf8DecodeEncodeToMbConvertEncodingRector;
use Rector\CodeQuality\Rector\Assign\CombinedAssignRector;
use Rector\CodeQuality\Rector\For_\ForRepeatedCountToOwnVariableRector;
use Rector\CodeQuality\Rector\FuncCall\ArrayMergeOfNonArraysToSimpleArrayRector;
Expand Down Expand Up @@ -36,9 +37,25 @@
__DIR__ . '/src/SonsOfPHP/*/*/*/*/vendor/*',
])
// This should be the same version that is found in composer.json file
->withPhpSets()
->withPreparedSets(typeDeclarations: true)
->withImportNames()
->withPhpSets(
php82: true,
)
->withPreparedSets(
deadCode: true,
codeQuality: true,
codingStyle: true,
typeDeclarations: true,
//privatization: true,
//naming: true,
instanceOf: true,
earlyReturn: true,
strictBooleans: true,
phpunitCodeQuality: true,
)
->withImportNames(
importShortClasses: false,
removeUnusedImports: true,
)
->withRules([
// Generic
AddVoidReturnTypeWhereNoReturnRector::class,
Expand All @@ -51,6 +68,7 @@
ExplicitBoolCompareRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
ForRepeatedCountToOwnVariableRector::class,
Utf8DecodeEncodeToMbConvertEncodingRector::class,
// PHPUnit Rules
AnnotationWithValueToAttributeRector::class,
AssertCompareToSpecificMethodRector::class,
Expand Down
2 changes: 2 additions & 0 deletions src/SonsOfPHP/Bard/src/Console/Command/AddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (null === $packages = $bardConfig->getSection('packages')) {
$packages = [];
}

foreach ($packages as $pkg) {
if ($pkg['path'] === $input->getArgument('path')) {
$io->error([
Expand All @@ -60,6 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return self::FAILURE;
}
}

$packages[] = [
'path' => $input->getArgument('path'),
'repository' => $input->getArgument('repository'),
Expand Down
2 changes: 2 additions & 0 deletions src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (!is_file($sourceFile)) {
throw new RuntimeException(sprintf('The file "%s" is an invalid file.', $sourceFile));
}

// ---

// ---
Expand All @@ -70,6 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->getHelper('process')->run($output, $process);
}
}

// ---

$io->success(sprintf('File "%s" has been copied to all managed repos.', $sourceFile));
Expand Down
3 changes: 3 additions & 0 deletions src/SonsOfPHP/Bard/src/Console/Command/MergeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
final class MergeCommand extends AbstractCommand
{
private readonly Json $json;

private array $bardConfig;

private string $mainComposerFile;

private ?HelperInterface $formatter = null;

public function __construct()
Expand Down
2 changes: 1 addition & 1 deletion src/SonsOfPHP/Bard/src/Console/Command/PullCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$bardConfig = new JsonFile($input->getOption('working-dir') . '/bard.json');
$formatter = $this->getHelper('formatter');
$this->getHelper('formatter');
$io = new SymfonyStyle($input, $output);

foreach ($bardConfig->getSection('packages') as $pkg) {
Expand Down
12 changes: 11 additions & 1 deletion src/SonsOfPHP/Bard/src/Console/Command/ReleaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SonsOfPHP\Bard\JsonFile;
use SonsOfPHP\Bard\Worker\File\Bard\UpdateVersion;
use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateReplaceSection;
use SonsOfPHP\Component\Json\Json;
use SonsOfPHP\Component\Version\Version;
use SonsOfPHP\Component\Version\VersionInterface;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -26,7 +25,9 @@
final class ReleaseCommand extends AbstractCommand
{
private JsonFile $bardConfig;

private VersionInterface|Version|null $releaseVersion = null;

private bool $isDryRun = true;

protected function configure(): void
Expand Down Expand Up @@ -91,6 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($this->isDryRun) {
$io->note('dry-run enabled no changes will be made');
}

$io->text([
sprintf('Bumping release from <info>%s</> to <info>%s</>', $this->bardConfig->getSection('version'), $this->releaseVersion->toString()),
]);
Expand All @@ -114,12 +116,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
]);
$rootComposerJsonFile = $rootComposerJsonFile->with(new UpdateReplaceSection($pkgComposerJsonFile));
}

$output->writeln([
'saving root composer.json',
]);
if (!$this->isDryRun) {
file_put_contents($rootComposerJsonFile->getFilename(), $rootComposerJsonFile->toJson());
}

$output->writeln([
'root composer.json file saved',
]);
Expand All @@ -134,6 +138,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// 3. Tag Release and push
$io->newLine();
$io->section(sprintf('updating mother repo for release %s', $this->releaseVersion->toString()));

$processCommands = [
['git', 'add', '.'],
['git', 'commit', '--allow-empty', '-m', sprintf('"Preparing for Release v%s"', $this->releaseVersion->toString())],
Expand All @@ -148,6 +153,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->getHelper('process')->mustRun($output, $process, sprintf('There was and error running command: %s', $process->getCommandLine()));
}
}

$io->success('Mother Repository Released');

// 4. Subtree Split for each package
Expand Down Expand Up @@ -175,8 +181,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->getHelper('process')->mustRun($output, $process, sprintf('There was and error running command: %s', $process->getCommandLine()));
}
}

$io->newLine();
}

$io->text('All Packages have been Released');
// $io->success('All Packages have been Released');

Expand All @@ -186,10 +194,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// 6. Update bard.json with current version
$io->section('Updating version in bard.json');

$this->bardConfig = $this->bardConfig->with(new UpdateVersion($this->releaseVersion));
if (!$this->isDryRun) {
file_put_contents($this->bardConfig->getFilename(), $this->bardConfig->toJson());
}

$io->text('bard.json updated with new version');

// 7. Commit and push updates
Expand Down
1 change: 1 addition & 0 deletions src/SonsOfPHP/Bard/src/JsonFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
final class JsonFile
{
private array $config = [];

private Json $json;

public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile
if (!isset($rootAutoloadSection['psr-4'])) {
$rootAutoloadSection['psr-4'] = [];
}

foreach ($config as $namespace => $pkgPath) {
$rootAutoloadSection['psr-4'][$namespace] = trim($path . '/' . trim((string) $pkgPath, '/'), '/');
}
Expand All @@ -37,6 +38,7 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile
if (!isset($rootAutoloadSection['exclude-from-classmap'])) {
$rootAutoloadSection['exclude-from-classmap'] = [];
}

foreach ($config as $pkgPath) {
$rootAutoloadSection['exclude-from-classmap'][] = trim($path . '/' . trim((string) $pkgPath, '/'), '/');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile
if (array_key_exists($package, $rootRequireDev)) {
unset($rootRequireDev[$package]);
}

continue;
}

Expand All @@ -45,6 +46,7 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile
if (array_key_exists($package, $rootRequire)) {
unset($rootRequire[$package]);
}

continue;
}

Expand Down
10 changes: 6 additions & 4 deletions src/SonsOfPHP/Bridge/Aws/Filesystem/Adapter/S3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function add(string $path, mixed $contents, ?ContextInterface $context =
if (isset($context['mimeType'])) {
$options['params']['ContentType'] = $context['mimeType'];
}

try {
$this->client->upload(
$this->bucket,
Expand All @@ -49,8 +50,8 @@ public function add(string $path, mixed $contents, ?ContextInterface $context =
$context['acl'] ?? $this->acl,
$options,
);
} catch (Throwable $exception) {
throw new UnableToWriteFileException($exception->getMessage());
} catch (Throwable $throwable) {
throw new UnableToWriteFileException($throwable->getMessage());
}
}

Expand Down Expand Up @@ -81,8 +82,8 @@ public function remove(string $path, ?ContextInterface $context = null): void

try {
$this->client->execute($command);
} catch (Throwable $exception) {
throw new UnableToDeleteFileException($exception->getMessage());
} catch (Throwable $throwable) {
throw new UnableToDeleteFileException($throwable->getMessage());
}
}

Expand Down Expand Up @@ -134,6 +135,7 @@ public function isDirectory(string $path, ?ContextInterface $context = null): bo
if ($result->hasKey('Contents')) {
return true;
}

return $result->hasKey('CommonPrefixes');
} catch (Throwable) {
throw new FilesystemException('Could not figure out if directory exists');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
final class S3AdapterTest extends TestCase
{
private StreamInterface $stream;

private ResultInterface $result;

private CommandInterface $command;

private S3ClientInterface $client;

private AdapterInterface $adapter;

protected function setUp(): void
Expand Down Expand Up @@ -58,14 +62,14 @@ public function testItWillUploadFile(): void
public function testItCanGetFileContents(): void
{
$this->stream->method('getContents')->willReturn('file contents');

Check failure on line 64 in src/SonsOfPHP/Bridge/Aws/Filesystem/Tests/Adapter/S3AdapterTest.php

View workflow job for this annotation

GitHub Actions / Psalm (8.2)

UndefinedInterfaceMethod

src/SonsOfPHP/Bridge/Aws/Filesystem/Tests/Adapter/S3AdapterTest.php:64:24: UndefinedInterfaceMethod: Method Psr\Http\Message\StreamInterface::method does not exist (see https://psalm.dev/181)
$this->result->method('get')->with($this->equalTo('Body'))->willReturn($this->stream);
$this->result->method('get')->with('Body')->willReturn($this->stream);

Check failure on line 65 in src/SonsOfPHP/Bridge/Aws/Filesystem/Tests/Adapter/S3AdapterTest.php

View workflow job for this annotation

GitHub Actions / Psalm (8.2)

UndefinedInterfaceMethod

src/SonsOfPHP/Bridge/Aws/Filesystem/Tests/Adapter/S3AdapterTest.php:65:24: UndefinedInterfaceMethod: Method Aws\ResultInterface::method does not exist (see https://psalm.dev/181)

$this->assertSame('file contents', $this->adapter->get('/path/to/file.ext'));
}

public function testItCanRemoveFile(): void
{
$this->client->expects($this->once())->method('getCommand')->with($this->equalTo('DeleteObject'))->willReturn($this->command);
$this->client->expects($this->once())->method('getCommand')->with('DeleteObject')->willReturn($this->command);

Check failure on line 72 in src/SonsOfPHP/Bridge/Aws/Filesystem/Tests/Adapter/S3AdapterTest.php

View workflow job for this annotation

GitHub Actions / Psalm (8.2)

UndefinedInterfaceMethod

src/SonsOfPHP/Bridge/Aws/Filesystem/Tests/Adapter/S3AdapterTest.php:72:48: UndefinedInterfaceMethod: Method Aws\ResultInterface::method does not exist (see https://psalm.dev/181)

$this->adapter->remove('/path/to/file.ext');
}
Expand Down Expand Up @@ -123,7 +127,7 @@ public function testItCanRemoveDirectory(): void
public function testItCanMoveFile(): void
{
$this->client->expects($this->once())->method('copy');
$this->client->expects($this->once())->method('getCommand')->with($this->equalTo('DeleteObject'))->willReturn($this->command);
$this->client->expects($this->once())->method('getCommand')->with('DeleteObject')->willReturn($this->command);

$this->adapter->move('/path/to/source.ext', '/path/to/destination.ext');
}
Expand All @@ -132,7 +136,7 @@ public function testItCanReturnContentType(): void
{
$this->result
->method('get')
->with($this->equalTo('ContentType'))
->with('ContentType')
->willReturn('text/plain');

$this->assertSame('text/plain', $this->adapter->mimeType('/path/to/source.ext'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
final class QueryBuilderAdapterTest extends TestCase
{
private MockObject $builder;

private MockObject $result;

public function setUp(): void
protected function setUp(): void
{
$this->builder = $this->createMock(QueryBuilder::class);
$this->result = $this->createMock(Result::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace SonsOfPHP\Bridge\Doctrine\EventSourcing;

use Doctrine\DBAL\Connection;
use Generator;
use SonsOfPHP\Component\EventSourcing\Aggregate\AggregateId;
use SonsOfPHP\Component\EventSourcing\Aggregate\AggregateIdInterface;
use SonsOfPHP\Component\EventSourcing\Aggregate\AggregateVersion;
Expand All @@ -26,12 +25,8 @@ public function __construct(private readonly Connection $connection, private rea

public function persist(MessageInterface $message): void
{
$id = $message->getAggregateId();
$version = $message->getAggregateVersion();

if (!$id instanceof AggregateIdInterface || !$version instanceof AggregateVersionInterface) {
throw new EventSourcingException('No ID or Verion');
}
$message->getAggregateId();
$message->getAggregateVersion();

$data = $this->serializer->serialize($message);

Expand All @@ -44,7 +39,7 @@ public function persist(MessageInterface $message): void
Metadata::TIMESTAMP_FORMAT,
];

if (\count($requiredMetadata) != \count(array_intersect_key(array_flip($requiredMetadata), $data['metadata']))) {
if (\count($requiredMetadata) !== \count(array_intersect_key(array_flip($requiredMetadata), $data['metadata']))) {
throw new EventSourcingException('metadata is missing one or more required values');
}

Expand Down
3 changes: 0 additions & 3 deletions src/SonsOfPHP/Bridge/Doctrine/EventSourcing/TableSchemaV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
namespace SonsOfPHP\Bridge\Doctrine\EventSourcing;

use DateTimeImmutable;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
use SonsOfPHP\Component\EventSourcing\Metadata;

Expand Down
2 changes: 0 additions & 2 deletions src/SonsOfPHP/Bridge/Doctrine/EventSourcing/TableSchemaV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace SonsOfPHP\Bridge\Doctrine\EventSourcing;

use DateTimeImmutable;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
use SonsOfPHP\Component\EventSourcing\Metadata;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
final class DoctrineDbalMessageRepositoryTest extends TestCase
{
private Connection $connection;

private MessageSerializerInterface $messageSerializer;

private TableSchemaInterface $tableSchema;

protected function setUp(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class QueryBuilderAdapterTest extends TestCase
{
private MockObject $builder;

public function setUp(): void
protected function setUp(): void
{
$this->builder = $this->createMock(QueryBuilder::class);
}
Expand Down
Loading

0 comments on commit 4ad8b79

Please sign in to comment.