Skip to content

Commit

Permalink
refactor: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
avardugin committed Aug 22, 2024
1 parent d4f5646 commit 0901c01
Show file tree
Hide file tree
Showing 25 changed files with 55 additions and 56 deletions.
4 changes: 1 addition & 3 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
realpath(__DIR__.'/../')
);

$env = $app->detectEnvironment(function()
{
$env = $app->detectEnvironment(function () {
return getenv('APP_ENV') ?: 'local';
});
$fn = ".env.{$env}";

$app->loadEnvironmentFrom(file_exists(base_path($fn)) ? $fn : '.env');


return $app;
2 changes: 1 addition & 1 deletion src/Contracts/VersionEnumContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ interface VersionEnumContract
public static function values(): array;

public static function toString(string $separator = ','): string;
}
}
16 changes: 8 additions & 8 deletions src/Importers/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

class Importer
{
const DELETED_AT_FIELD = 'deleted_at';
public const DELETED_AT_FIELD = 'deleted_at';

const ITEMS_TO_CREATE = 'create';
const ITEMS_TO_UPDATE = 'update';
public const ITEMS_TO_CREATE = 'create';
public const ITEMS_TO_UPDATE = 'update';

const CREATED_REPORTS = 'created';
const UPDATED_REPORTS = 'updated';
public const CREATED_REPORTS = 'created';
public const UPDATED_REPORTS = 'updated';

protected $input;

Expand All @@ -27,13 +27,13 @@ class Importer

protected $items = [
self::ITEMS_TO_CREATE => [],
self::ITEMS_TO_UPDATE => []
self::ITEMS_TO_UPDATE => [],
];

protected $report = [
self::UPDATED_REPORTS => 0,
self::CREATED_REPORTS => 0,
'errors' => []
'errors' => [],
];

public function setInput($input): self
Expand Down Expand Up @@ -190,7 +190,7 @@ protected function validateDuplicatingOfId(array $item): bool
}

return $this->service->withTrashed()->exists([
'id' => $item['id']
'id' => $item['id'],
]);
}

Expand Down
2 changes: 0 additions & 2 deletions src/Interfaces/ExporterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ public function setFileName(string $fileName);
*/
public function setType(string $type): self;
}


6 changes: 3 additions & 3 deletions src/Middleware/SecurityMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class SecurityMiddleware
{
protected $cache;

const MAINTENANCE_MODE_KEY = 'maintenance_activated';
const MAINTENANCE_MODE_HEADER = 'maintenance';
public const MAINTENANCE_MODE_KEY = 'maintenance_activated';
public const MAINTENANCE_MODE_HEADER = 'maintenance';

public function __construct(Repository $cache)
{
Expand Down Expand Up @@ -66,7 +66,7 @@ protected function codeVariations(): array
Response::HTTP_INSUFFICIENT_STORAGE,
Response::HTTP_LOOP_DETECTED,
Response::HTTP_NOT_EXTENDED,
Response::HTTP_NETWORK_AUTHENTICATION_REQUIRED
Response::HTTP_NETWORK_AUTHENTICATION_REQUIRED,
];
}
}
4 changes: 2 additions & 2 deletions src/Services/HttpRequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected function sendRequest($method, $url, array $data = [], array $headers =
case 'delete':
$response = $client->delete($url, $this->options);
break;
default :
default:
throw new UnknownRequestMethodException($method);
}

Expand All @@ -172,7 +172,7 @@ protected function logRequest(string $typeOfRequest, string $url, array $data, a
logger("sending {$typeOfRequest} request:", [
'url' => $url,
'data' => $data,
'headers' => $headers
'headers' => $headers,
]);
logger('');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/ModelTestState.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function assertNotChanged(): void
$this->assertEquals([
'updated' => [],
'created' => [],
'deleted' => []
'deleted' => [],
], $changes);
}

Expand Down Expand Up @@ -71,7 +71,7 @@ protected function getChanges(): array
return [
'updated' => $this->prepareChanges($updatedRecords),
'created' => $this->prepareChanges($updatedData->values()->toArray()),
'deleted' => $this->prepareChanges($deletedRecords)
'deleted' => $this->prepareChanges($deletedRecords),
];
}

Expand Down
6 changes: 3 additions & 3 deletions src/Traits/EntityControlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ protected function getQuery($where = []): Query

if (!empty($this->attachedRelationsCount)) {
foreach ($this->attachedRelationsCount as $requestedRelations) {
list ($countRelation, $relation) = extract_last_part($requestedRelations);
list($countRelation, $relation) = extract_last_part($requestedRelations);

if (empty($relation)) {
$query->withCount($countRelation);
} else {
$query->with([
$relation => function ($query) use ($countRelation) {
$query->withCount($countRelation);
}
},
]);
}
}
Expand Down Expand Up @@ -465,4 +465,4 @@ protected function resetSettableProperties(bool $value = true): void
{
$this->shouldSettablePropertiesBeReset = $value;
}
}
}
4 changes: 2 additions & 2 deletions src/Traits/MailsMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait MailsMockTrait

private array $requiredExpectationParameters = [
'emails',
'fixture'
'fixture',
];

/**
Expand Down Expand Up @@ -228,4 +228,4 @@ protected function assertAttachments(array $currentMail, Mailable $mail, int $in
}
}
}
}
}
3 changes: 2 additions & 1 deletion src/Traits/MigrationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function (Blueprint $table) use ($toEntity, $needAddField, $onDelete) {
->references('id')
->on($this->getTableName($toEntity))
->onDelete($onDelete);
});
}
);
}

public function dropForeignKey($fromEntity, $toEntity, $needDropField = false)
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/ModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait ModelTrait

public static function getFields(): array
{
$model = (new static);
$model = (new static());

$keyName = $model->getKeyName();
$guarded = $model->getGuarded();
Expand Down Expand Up @@ -132,7 +132,7 @@ protected function prepareRelations(string $relations): array
return explode('.', $relations);
} else {
return [
$relations
$relations,
];
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Traits/SearchTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ trait SearchTrait
'all',
'per_page',
'page',
'desc'
'desc',
];

protected function setAdditionalReservedFilters(...$filterNames)
Expand Down Expand Up @@ -87,7 +87,7 @@ public function filterByQuery(array $fields, string $mask = "'%{{ value }}%'"):
$this->query->where(function ($query) use ($fields, $mask) {
foreach ($fields as $field) {
if (Str::contains($field, '.')) {
list ($fieldName, $relations) = extract_last_part($field);
list($fieldName, $relations) = extract_last_part($field);

$query->orWhereHas($relations, function ($query) use ($fieldName, $mask) {
$query->where(
Expand Down Expand Up @@ -183,7 +183,7 @@ public function wrapPaginatedData(Collection $data): LengthAwarePaginator

$paginator = new LengthAwarePaginator($data, $total, $perPage, 1, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page'
'pageName' => 'page',
]);

return $this->getModifiedPaginator($paginator);
Expand Down Expand Up @@ -348,7 +348,7 @@ protected function constructWhere(Query $query, $where = [], ?string $field = nu
$field = (empty($field)) ? $this->primaryKey : $field;

$where = [
$field => $where
$field => $where,
];
}

Expand All @@ -362,7 +362,7 @@ protected function constructWhere(Query $query, $where = [], ?string $field = nu
protected function applyWhereCallback(Query $query, string $field, Closure $callback): void
{
if (Str::contains($field, '.')) {
list ($conditionField, $relations) = extract_last_part($field);
list($conditionField, $relations) = extract_last_part($field);

$query->whereHas($relations, function ($q) use ($callback, $conditionField) {
$callback($q, $conditionField);
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/TranslationUpdateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RonasIT\Support\Traits;

use Illuminate\Support\Arr;
use Illuminate\Support\Arr;

trait TranslationUpdateTrait
{
Expand All @@ -14,7 +14,7 @@ public function updateWithTranslations($id, $data)
return $this->update(['id' => $id], $data);
}

$modelInstance = new $this->model;
$modelInstance = new $this->model();

$foreignKey = $modelInstance->allTranslations()->getForeignKeyName();

Expand All @@ -23,7 +23,7 @@ public function updateWithTranslations($id, $data)
foreach ($translations as $translation) {
$translationModel::where([
$foreignKey => $id,
'locale' => $translation['locale']
'locale' => $translation['locale'],
])->update($translation);
}

Expand Down
5 changes: 3 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ function getGUID(): string
mt_srand((double)microtime() * 10000);//optional for php 4.2.0 and up.
$charId = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"

return chr(123)// "{"
. substr($charId, 0, 8) . $hyphen
. substr($charId, 8, 4) . $hyphen
Expand Down Expand Up @@ -243,7 +244,7 @@ function clear_folder(string $path): void

/**
* Builds an associative array by gotten keys and values
*
*
* @param array $array
* @param callable $callback - should return associate array with "key" and "value" keys
*
Expand All @@ -256,7 +257,7 @@ function clear_folder(string $path): void
* }
*
* @return array
*
*
* @deprecated Use array_walk, forEach or mapWithKeys instead
*/
function array_associate(array $array, callable $callback): array
Expand Down
2 changes: 1 addition & 1 deletion tests/EntityControlTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function testUpdateOrCreateEntityExists()
->withCount('relation')
->updateOrCreate(1, ['name' => 'test_name']);

$this->assertSettablePropertiesReset(self::$testRepositoryClass);
$this->assertSettablePropertiesReset(self::$testRepositoryClass);
}

public function testUpdateOrCreateEntityDoesntExist()
Expand Down
8 changes: 4 additions & 4 deletions tests/support/Enum/VersionEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
// Backward compatibility with PHP < 8
class VersionEnum implements VersionEnumContract
{
const v1 = '1';
const v2 = '2';
const v3 = '3';
public const v1 = '1';
public const v2 = '2';
public const v3 = '3';

public static function values(): array
{
Expand All @@ -20,4 +20,4 @@ public static function toString(string $separator = ','): string
{
return implode($separator, self::values());
}
}
}
2 changes: 1 addition & 1 deletion tests/support/Mock/ChildRelationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

class ChildRelationModel extends Model
{
}
}
2 changes: 1 addition & 1 deletion tests/support/Mock/RelationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public function child_relation(): HasMany
{
return $this->hasMany(ChildRelationModel::class);
}
}
}
2 changes: 1 addition & 1 deletion tests/support/Mock/TestMailWithAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public function assertHasAttachment($file, array $options = []): bool
{
return true;
}
}
}
7 changes: 4 additions & 3 deletions tests/support/Mock/TestModelNoPrimaryKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

class TestModelNoPrimaryKey extends Model
{
use ModelTrait, SoftDeletes;
use ModelTrait;
use SoftDeletes;

protected $primaryKey = null;

protected $fillable = [
'name',
'json_field',
'castable_field'
'castable_field',
];
}
}
3 changes: 2 additions & 1 deletion tests/support/Mock/TestModelWithoutJsonFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class TestModelWithoutJsonFields extends Model
{
use ModelTrait, SoftDeletes;
use ModelTrait;
use SoftDeletes;

protected $fillable = [
'name',
Expand Down
2 changes: 1 addition & 1 deletion tests/support/Mock/TestRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ public function getModelName(): string
{
return $this->getEntityName();
}
}
}
2 changes: 1 addition & 1 deletion tests/support/Mock/TestRepositoryNoPrimaryKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public function __construct()
{
$this->setModel(TestModelNoPrimaryKey::class);
}
}
}
2 changes: 1 addition & 1 deletion tests/support/Traits/RouteMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ protected function mockRouteFacadeVersion(): void
});
});
}
}
}
Loading

0 comments on commit 0901c01

Please sign in to comment.