Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Apply fixes from StyleCI (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldyrynda authored Oct 24, 2021
1 parent 06ba6a7 commit 5f4a838
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 65 deletions.
44 changes: 22 additions & 22 deletions src/Rules/EfficientUuidExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@

namespace Dyrynda\Database\Rules;

use Ramsey\Uuid\Uuid;
use Illuminate\Contracts\Validation\Rule;
use Ramsey\Uuid\Uuid;

class EfficientUuidExists implements Rule
{
/** @var \Dyrynda\Database\GeneratesUuid */
protected $model;
/** @var \Dyrynda\Database\GeneratesUuid */
protected $model;

/** @var string */
protected $column;
/** @var string */
protected $column;

public function __construct(string $model, string $column = 'uuid')
{
$this->model = new $model;
public function __construct(string $model, string $column = 'uuid')
{
$this->model = new $model;

$this->column = $column;
}
$this->column = $column;
}

public function passes($attribute, $value): bool
{
if (Uuid::isValid($value)) {
$binaryUuid = Uuid::fromString(strtolower($value))->getBytes();
public function passes($attribute, $value): bool
{
if (Uuid::isValid($value)) {
$binaryUuid = Uuid::fromString(strtolower($value))->getBytes();

return $this->model->where($this->column, $binaryUuid)->exists();
}
return $this->model->where($this->column, $binaryUuid)->exists();
}

return false;
}
return false;
}

public function message(): string
{
return trans('validation.exists');
}
public function message(): string
{
return trans('validation.exists');
}
}
6 changes: 3 additions & 3 deletions tests/EfficientUuidExistsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EfficientUuidExistsRuleTest extends TestCase
/** @test */
public function it_passes_valid_existing_uuid()
{
/** @var \Tests\Fixtures\EfficientUuidPost $post */
/** @var \Tests\Fixtures\EfficientUuidPost $post */
$post = factory(EfficientUuidPost::class)->create();

$rule = new EfficientUuidExists(EfficientUuidPost::class);
Expand All @@ -32,7 +32,7 @@ public function it_fails_on_non_existing_uuid()
/** @test */
public function it_fails_on_any_non_uuid_invalid_strings()
{
$uuid = "1235123564354633";
$uuid = '1235123564354633';

$rule = new EfficientUuidExists(EfficientUuidPost::class, 'uuid');

Expand All @@ -42,7 +42,7 @@ public function it_fails_on_any_non_uuid_invalid_strings()
/** @test */
public function it_works_with_custom_uuid_column_name()
{
/** @var \Tests\Fixtures\EfficientUuidPost $post */
/** @var \Tests\Fixtures\EfficientUuidPost $post */
$post = factory(EfficientUuidPost::class)->create();

$rule = new EfficientUuidExists(EfficientUuidPost::class, 'custom_uuid');
Expand Down
22 changes: 11 additions & 11 deletions tests/Fixtures/EfficientUuidPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

namespace Tests\Fixtures;

use Illuminate\Database\Eloquent\Model;
use Dyrynda\Database\Casts\EfficientUuid;
use Dyrynda\Database\Support\GeneratesUuid;
use Illuminate\Database\Eloquent\Model;

class EfficientUuidPost extends Model
{
use GeneratesUuid;
use GeneratesUuid;

protected $table = 'posts';
protected $table = 'posts';

public $timestamps = false;
public $timestamps = false;

protected $casts = [
'uuid' => EfficientUuid::class,
protected $casts = [
'uuid' => EfficientUuid::class,
'custom_uuid' => EfficientUuid::class,
];
];

public function uuidColumn(): string
{
return 'uuid';
}
public function uuidColumn(): string
{
return 'uuid';
}

public function uuidColumns(): array
{
Expand Down
58 changes: 29 additions & 29 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@

namespace Tests;

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Dyrynda\Database\LaravelEfficientUuidServiceProvider;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class TestCase extends \Orchestra\Testbench\TestCase
{
protected function setUp(): void
{
parent::setUp();

$this->withFactories(realpath(__DIR__ . '/database/factories'));

$this->setupDatabase($this->app);
}

protected function getPackageProviders($app)
{
return [
LaravelEfficientUuidServiceProvider::class,
];
}

protected function setupDatabase($app)
{
Schema::dropAllTables();

$app['db']->connection()->getSchemaBuilder()->create('posts', function (Blueprint $table) {
$table->increments('id');
$table->efficientUuid('uuid');
$table->efficientUuid('custom_uuid');
$table->string('title');
});
}
protected function setUp(): void
{
parent::setUp();

$this->withFactories(realpath(__DIR__.'/database/factories'));

$this->setupDatabase($this->app);
}

protected function getPackageProviders($app)
{
return [
LaravelEfficientUuidServiceProvider::class,
];
}

protected function setupDatabase($app)
{
Schema::dropAllTables();

$app['db']->connection()->getSchemaBuilder()->create('posts', function (Blueprint $table) {
$table->increments('id');
$table->efficientUuid('uuid');
$table->efficientUuid('custom_uuid');
$table->string('title');
});
}
}

0 comments on commit 5f4a838

Please sign in to comment.