Skip to content

Commit

Permalink
Merge pull request #158 from leroy-merlin-br/chore/bump-mongolid-version
Browse files Browse the repository at this point in the history
chore(deps): bump mongolid to v3.4
  • Loading branch information
orlandocavassani authored Dec 21, 2022
2 parents 3509ce9 + 96954b1 commit 558a606
Show file tree
Hide file tree
Showing 35 changed files with 1,018 additions and 434 deletions.
1 change: 0 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
strategy:
matrix:
php:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build
.phpunit.result.cache
phpcs.xml
.idea
docker-compose.override.yml
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
}
],
"require": {
"php": ">=7.3",
"leroy-merlin-br/mongolid": "v3.3-beta2",
"php": ">=7.4",
"leroy-merlin-br/mongolid": "v3.4",
"illuminate/support": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"illuminate/auth": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"illuminate/queue": "^5.4 || ^6.0 || ^7.0 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.25",
"phpunit/phpunit": "^9.5.27",
"orchestra/testbench": "^6.25.1",
"mockery/mockery": "^1.5.1",
"leroy-merlin-br/coding-standard": "^3.0.2"
"leroy-merlin-br/coding-standard": "^3.1.0"
},
"autoload": {
"psr-4": {
Expand Down
887 changes: 562 additions & 325 deletions composer.lock

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
FROM leroymerlinbr/php:7.3
FROM php:7.4-fpm
LABEL maintainer="[email protected]"

USER root:root

RUN docker-php-ext-enable xdebug
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

RUN apt-get update -qq \
&& apt-get install -qq --no-install-recommends \
git zip unzip \
libzip-dev libssl-dev \
zlib1g-dev libicu-dev \
&& apt-get clean

RUN pecl install xdebug-3.1.6 mongodb \
&& docker-php-ext-enable \
mongodb xdebug \
&& docker-php-ext-configure \
intl \
&& docker-php-ext-install \
intl pcntl zip \
&& rm -rf /tmp/*

ARG UID=1000
ARG GID=1000

RUN groupmod -g ${GID} www-data \
&& usermod -u ${UID} -g www-data www-data \
&& mkdir -p /var/www/html \
&& chown -hR www-data:www-data \
/var/www \
/usr/local/

COPY custom.ini /usr/local/etc/php/conf.d/custom.ini

USER www-data:www-data

WORKDIR /var/www/html
ENV PATH=$PATH:/var/www/.composer/vendor/bin
31 changes: 31 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,37 @@
<exclude-pattern>src/MongolidModel.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
<exclude-pattern>src/LaravelCacheComponent.php</exclude-pattern>
<exclude-pattern>src/MigrationServiceProvider.php</exclude-pattern>
<exclude-pattern>src/MongolidServiceProvider.php</exclude-pattern>
<exclude-pattern>src/Validation/Rules.php</exclude-pattern>
<exclude-pattern>src/Migrations/Migration.php</exclude-pattern>
<exclude-pattern>src/MongolidFailedJobProvider.php</exclude-pattern>
<exclude-pattern>src/Migrations/Commands/MigrateCommand.php</exclude-pattern>
<exclude-pattern>src/Migrations/Commands/FreshCommand.php</exclude-pattern>
<exclude-pattern>src/Migrations/Commands/InstallCommand.php</exclude-pattern>
<exclude-pattern>src/Migrations/MigrationCreator.php</exclude-pattern>
<exclude-pattern>src/Migrations/Commands/RollbackCommand.php</exclude-pattern>
<exclude-pattern>src/Migrations/Commands/MigrateMakeCommand.php</exclude-pattern>
<exclude-pattern>src/Migrations/Commands/StatusCommand.php</exclude-pattern>
<exclude-pattern>src/LaravelEventTrigger.php</exclude-pattern>
<exclude-pattern>src/FailedJobsService.php</exclude-pattern>
<exclude-pattern>src/Migrations/Commands/RefreshCommand.php</exclude-pattern>
<exclude-pattern>src/MongolidUserProvider.php</exclude-pattern>
<exclude-pattern>src/Migrations/MongolidMigrationRepository.php</exclude-pattern>
<exclude-pattern>src/LegacyMongolidModel.php</exclude-pattern>
<exclude-pattern>src/Migrations/Migrator.php</exclude-pattern>
<exclude-pattern>src/Migrations/Commands/ResetCommand.php</exclude-pattern>
<exclude-pattern>src/Migrations/Commands/ResetCommand.php</exclude-pattern>
<exclude-pattern>src/MongolidModel.php</exclude-pattern>
<exclude-pattern>tests/Stubs</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference.ClassNameReferencedViaFunctionCall">
<exclude-pattern>tests/MongolidUserProviderTest.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint">
<type>warning</type>
</rule>
Expand Down
5 changes: 4 additions & 1 deletion src/LaravelCacheComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public function get(string $key)
return $this->inMemoryCache[$key];
}

return $this->inMemoryCache[$key] = $this->laravelCache->get($key, null);
return $this->inMemoryCache[$key] = $this->laravelCache->get(
$key,
null
);
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/LegacyMongolidModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ public function isValid()
}

// Creates validator with attributes and the rules of the object
$validator = app(ValidationFactory::class)->make($attributes, $rules, $this->messages());
$validator = app(ValidationFactory::class)->make(
$attributes,
$rules,
$this->messages()
);

// Validate and attach errors
if ($hasErrors = $validator->fails()) {
Expand Down Expand Up @@ -335,7 +339,9 @@ protected function localMockShouldReceive(string $method)
*/
protected function localMockHasExpectationsFor(string $method): bool
{
return $this->hasLocalMock() && $this->getLocalMock()->mockery_getExpectationsFor($method);
return $this->hasLocalMock() && $this->getLocalMock()->mockery_getExpectationsFor(
$method
);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/MigrationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ protected function registerRepository()
function ($app) {
$collection = $app['config']['database.mongodb.default.migrations'] ?? 'migrations';

return new MongolidMigrationRepository($app[Connection::class], $collection);
return new MongolidMigrationRepository(
$app[Connection::class],
$collection
);
}
);
}
Expand Down Expand Up @@ -170,7 +173,9 @@ protected function registerMigrateInstallCommand()
$this->app->singleton(
'command.mongolid-migrate.install',
function ($app) {
return new InstallCommand($app['mongolid.migration.repository']);
return new InstallCommand(
$app['mongolid.migration.repository']
);
}
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Migrations/Commands/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ function ($path) {
*/
protected function usingRealPath()
{
return $this->input->hasOption('realpath') && $this->option('realpath');
return $this->input->hasOption('realpath') && $this->option(
'realpath'
);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Migrations/Commands/MigrateMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ protected function getMigrationPath()
*/
protected function usingRealPath()
{
return $this->input->hasOption('realpath') && $this->option('realpath');
return $this->input->hasOption('realpath') && $this->option(
'realpath'
);
}
}
4 changes: 3 additions & 1 deletion src/Migrations/Commands/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ protected function getStatusFor(array $ran, array $batches)
return Collection::make($this->getAllMigrationFiles())
->map(
function ($migration) use ($ran, $batches) {
$migrationName = $this->migrator->getMigrationName($migration);
$migrationName = $this->migrator->getMigrationName(
$migration
);

return in_array($migrationName, $ran)
? ['<info>Yes</info>', $migrationName, $batches[$migrationName]]
Expand Down
4 changes: 3 additions & 1 deletion src/Migrations/MigrationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public function getFilesystem()
protected function ensureMigrationDoesntAlreadyExist($name)
{
if (class_exists($className = $this->getClassName($name))) {
throw new InvalidArgumentException("A {$className} class already exists.");
throw new InvalidArgumentException(
"A {$className} class already exists."
);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ public function reset($paths = [])
*/
public function resolve($file)
{
$class = Str::studly(implode('_', array_slice(explode('_', $file), 4)));
$class = Str::studly(
implode('_', array_slice(explode('_', $file), 4))
);

return new $class($this->output);
}
Expand Down Expand Up @@ -407,7 +409,9 @@ protected function rollbackMigrations(array $migrations, $paths)
$migration = (object) $migration;

if (!$file = Arr::get($files, $migration->migration)) {
$this->note("<fg=red>Migration not found:</> {$migration->migration}");
$this->note(
"<fg=red>Migration not found:</> {$migration->migration}"
);

continue;
}
Expand Down
5 changes: 4 additions & 1 deletion src/MongolidFailedJobProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ private function presentJob($job)
'queue' => $job['queue'],
'payload' => $job['payload'],
'exception' => $job['exception'],
'failed_at' => LocalDateTime::format($job['failed_at'], DateTime::ATOM),
'failed_at' => LocalDateTime::format(
$job['failed_at'],
DateTime::ATOM
),
];
}
}
10 changes: 8 additions & 2 deletions src/MongolidModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ public function isValid()
}

// Creates validator with attributes and the rules of the object
$validator = app(ValidationFactory::class)->make($attributes, $rules, $this->messages());
$validator = app(ValidationFactory::class)->make(
$attributes,
$rules,
$this->messages()
);

// Validate and attach errors
if ($hasErrors = $validator->fails()) {
Expand Down Expand Up @@ -336,7 +340,9 @@ protected function localMockShouldReceive(string $method)
*/
protected function localMockHasExpectationsFor(string $method): bool
{
return $this->hasLocalMock() && $this->getLocalMock()->mockery_getExpectationsFor($method);
return $this->hasLocalMock() && $this->getLocalMock()->mockery_getExpectationsFor(
$method
);
}

/**
Expand Down
32 changes: 26 additions & 6 deletions src/MongolidServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ public function registerConnector()
$this->app->singleton(
Connection::class,
function ($app) {
$config = $app['config']->get('database.mongodb.default') ?? [];
$config = $app['config']->get(
'database.mongodb.default'
) ?? [];
$connectionString = $this->buildConnectionString($config);
$options = $config['options'] ?? [];
$driverOptions = $config['driver_options'] ?? [];

$connection = new Connection($connectionString, $options, $driverOptions);
$connection = new Connection(
$connectionString,
$options,
$driverOptions
);
$connection->defaultDatabase = $config['database'] ?? 'mongolid';

return $connection;
Expand All @@ -66,7 +72,9 @@ function ($app) {
EventTriggerService::class,
function ($app) {
$eventService = new EventTriggerService();
$eventService->registerEventDispatcher($app->make(LaravelEventTrigger::class));
$eventService->registerEventDispatcher(
$app->make(LaravelEventTrigger::class)
);

return $eventService;
}
Expand Down Expand Up @@ -113,7 +121,11 @@ protected function buildConnectionString(array $config): string

// If username is present, append "<username>:<password>@"
if (isset($config['username'])) {
$result .= sprintf('%s:%s@', $config['username'], $config['password'] ?? '');
$result .= sprintf(
'%s:%s@',
$config['username'],
$config['password'] ?? ''
);
}

// Append "<hostname>/<database>"
Expand Down Expand Up @@ -143,13 +155,21 @@ private function buildHostname(array $config): string
{
if (isset($config['cluster'])) {
foreach ($config['cluster']['nodes'] as $node) {
$nodes[] = sprintf('%s:%s', $node['host'] ?? '127.0.0.1', $node['port'] ?? 27017);
$nodes[] = sprintf(
'%s:%s',
$node['host'] ?? '127.0.0.1',
$node['port'] ?? 27017
);
}

return implode(',', $nodes ?? ['127.0.0.1:27017']);
}

return sprintf('%s:%s', $config['host'] ?? '127.0.0.1', $config['port'] ?? 27017);
return sprintf(
'%s:%s',
$config['host'] ?? '127.0.0.1',
$config['port'] ?? 27017
);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public function exists(string $attribute, $value, array $parameters)
$collection = $parameters[0];
$field = $parameters[1] ?? $attribute;

return $this->hasResults($collection, [$field => $this->transformIfId($value)]);
return $this->hasResults(
$collection,
[$field => $this->transformIfId($value)]
);
}

/**
Expand Down Expand Up @@ -127,7 +130,9 @@ public function objectIdMessage(string $message, string $attribute, string $rule
private function requireParameterCount(int $count, array $parameters, string $rule): void
{
if (count($parameters) < $count) {
throw new InvalidArgumentException("Validation rule {$rule} requires at least {$count} parameters.");
throw new InvalidArgumentException(
"Validation rule {$rule} requires at least {$count} parameters."
);
}
}

Expand Down
Loading

0 comments on commit 558a606

Please sign in to comment.