Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs.dist.php --allow-risky=yes
args: --config=.php-cs-fixer.dist.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
32 changes: 19 additions & 13 deletions .php_cs.dist.php → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@

$finder = Symfony\Component\Finder\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__.'/src',
__DIR__.'/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);
->ignoreVCS(true)
;

return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one']],
'combine_consecutive_unsets' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'single_trait_insert_per_statement' => true,
'single_quote' => true,
'trailing_comma_in_multiline' => true,
'unary_operator_spaces' => true,
])
->setFinder($finder);
->setFinder($finder)
;
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"require-dev": {
"brianium/paratest": "^6.2",
"friendsofphp/php-cs-fixer": "^3.8",
"nunomaduro/collision": "^5.3",
"orchestra/testbench": "^6.0|^7.0",
"phpunit/phpunit": "^9.3",
Expand Down
1 change: 0 additions & 1 deletion src/Bootstrap/BootRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
class BootRepository
{
/** * @var Repository */

public function __construct(
private string $repository
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/PublishAuthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function checkDirectory(string $path): self
*/
protected function copyDirectory(string $path, string $stubDirectory, string $format): self
{
$filesystem = new Filesystem;
$filesystem = new Filesystem();

collect($filesystem->allFiles(__DIR__ . $stubDirectory))
->each(function (SplFileInfo $file) use ($filesystem, $path, $format, $stubDirectory) {
Expand Down
1 change: 0 additions & 1 deletion src/Fields/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function __construct($relation, $parentRepository)
$this->repositoryClass = $parentRepository;
}


public function fillAttribute(RestifyRequest $request, $model, int $bulkRow = null)
{
/** * @var Model $relatedModel */
Expand Down
4 changes: 2 additions & 2 deletions src/Fields/Concerns/Attachable.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public function initializePivot(RestifyRequest $request, $relationship, $related

if ($relationship->withTimestamps) {
$pivot->forceFill([
$relationship->createdAt() => new DateTime,
$relationship->updatedAt() => new DateTime,
$relationship->createdAt() => new DateTime(),
$relationship->updatedAt() => new DateTime(),
]);
}

Expand Down
72 changes: 38 additions & 34 deletions src/Filters/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ public function __construct()
$this->booted();
}

protected function booted()
{
//
}

abstract public function filter(RestifyRequest $request, Builder | Relation $query, $value);
abstract public function filter(RestifyRequest $request, Builder|Relation $query, $value);

public function canSee(Closure $callback)
{
Expand All @@ -86,31 +81,7 @@ public function key(): string
return static::class;
}

protected function getType(): string
{
return $this->type;
}

protected function title(): string
{
if ($this->title) {
return $this->title;
}

if ($column = $this->column()) {
return Str::title(Str::snake(Str::studly($column), ' '));
}

return $this->title ?? Str::title(Str::snake(class_basename(static::class), ' '));
}

protected function description(): string
{
return $this->description;
}

/**
* @return string|null
* @deprecated use `column()` instead
*/
public function getColumn(): ?string
Expand Down Expand Up @@ -155,7 +126,9 @@ public function invalidPayloadValue(Request $request, $value)
{
if (is_array($value)) {
return count($value) < 1;
} elseif (is_string($value)) {
}

if (is_string($value)) {
return trim($value) === '';
}

Expand Down Expand Up @@ -188,6 +161,13 @@ public function setRepository(Repository $repository): self
return $this;
}

public function setTitle(string $title): self
{
$this->title = $title;

return $this;
}

public function repository(): ?Repository
{
if (! isset($this->repository)) {
Expand Down Expand Up @@ -222,8 +202,6 @@ public function getRelatedRepository(): ?array

/**
* Get the URI key for the filter.
*
* @return string
*/
public static function uriKey(): string
{
Expand Down Expand Up @@ -257,7 +235,6 @@ public function jsonSerialize()
]) : $initial;
});


if ($this->isAdvanced()) {
$serialized = array_merge($serialized, [
'rules' => $this->rules(app(Request::class)),
Expand All @@ -278,4 +255,31 @@ public function dd(): self

return $this;
}

protected function booted()
{
}

protected function getType(): string
{
return $this->type;
}

protected function title(): string
{
if ($this->title) {
return $this->title;
}

if ($column = $this->column()) {
return Str::title(Str::snake(Str::studly($column), ' '));
}

return $this->title ?? Str::title(Str::snake(class_basename(static::class), ' '));
}

protected function description(): string
{
return $this->description;
}
}
2 changes: 1 addition & 1 deletion src/Filters/SearchableFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SearchableFilter extends Filter
{
const TYPE = 'searchable';
public const TYPE = 'searchable';

public array $computedColumns = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public function __invoke(Request $request): JsonResponse

Password::deleteToken($user);

return data("Password has been successfully changed");
return data('Password has been successfully changed');
}
}
34 changes: 17 additions & 17 deletions src/Http/Controllers/RestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ class RestResponse extends JsonResponse implements Responsable
/**
* Response Codes.
*/
const REST_RESPONSE_AUTH_CODE = 401;
const REST_RESPONSE_REFRESH_CODE = 103;
const REST_RESPONSE_CREATED_CODE = 201;
const REST_RESPONSE_UPDATED_CODE = 200;
const REST_RESPONSE_DELETED_CODE = 204; // update or delete with success
const REST_RESPONSE_BLANK_CODE = 204;
const REST_RESPONSE_ERROR_CODE = 500;
const REST_RESPONSE_INVALID_CODE = 400;
const REST_RESPONSE_UNAUTHORIZED_CODE = 401;
const REST_RESPONSE_FORBIDDEN_CODE = 403;
const REST_RESPONSE_MISSING_CODE = 404;
const REST_RESPONSE_NOTFOUND_CODE = 404;
const REST_RESPONSE_THROTTLE_CODE = 429;
const REST_RESPONSE_SUCCESS_CODE = 200;
const REST_RESPONSE_UNAVAILABLE_CODE = 503;

const CODES = [
public const REST_RESPONSE_AUTH_CODE = 401;
public const REST_RESPONSE_REFRESH_CODE = 103;
public const REST_RESPONSE_CREATED_CODE = 201;
public const REST_RESPONSE_UPDATED_CODE = 200;
public const REST_RESPONSE_DELETED_CODE = 204; // update or delete with success
public const REST_RESPONSE_BLANK_CODE = 204;
public const REST_RESPONSE_ERROR_CODE = 500;
public const REST_RESPONSE_INVALID_CODE = 400;
public const REST_RESPONSE_UNAUTHORIZED_CODE = 401;
public const REST_RESPONSE_FORBIDDEN_CODE = 403;
public const REST_RESPONSE_MISSING_CODE = 404;
public const REST_RESPONSE_NOTFOUND_CODE = 404;
public const REST_RESPONSE_THROTTLE_CODE = 429;
public const REST_RESPONSE_SUCCESS_CODE = 200;
public const REST_RESPONSE_UNAVAILABLE_CODE = 503;

public const CODES = [
self::REST_RESPONSE_AUTH_CODE,
self::REST_RESPONSE_REFRESH_CODE,
self::REST_RESPONSE_CREATED_CODE,
Expand Down
1 change: 0 additions & 1 deletion src/Http/Requests/Concerns/DetermineRequestType.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Binaryk\LaravelRestify\Http\Requests\Concerns;

use Binaryk\LaravelRestify\Http\Requests\GlobalSearchRequest;
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelRestifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function register(): void

// Register the main class to use with the facade
$this->app->singleton('laravel-restify', function () {
return new Restify;
return new Restify();
});

$this->commands([
Expand Down
8 changes: 4 additions & 4 deletions src/Models/ActionLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class ActionLog extends Model
'changes' => 'array',
];

const STATUS_FINISHED = 'finished';
public const STATUS_FINISHED = 'finished';

const ACTION_CREATED = 'Stored';
const ACTION_UPDATED = 'Updated';
const ACTION_DELETED = 'Deleted';
public const ACTION_CREATED = 'Stored';
public const ACTION_UPDATED = 'Updated';
public const ACTION_DELETED = 'Deleted';

public static function forRepositoryStored(Model $model, Authenticatable $user = null, array $dirty = null): self
{
Expand Down
4 changes: 2 additions & 2 deletions src/Restify.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static function repositories(array $repositories)
(new BootRepository($repository))->boot();
});

return new static;
return new static();
}

/**
Expand All @@ -117,7 +117,7 @@ public static function repositoriesFrom(string $directory): void

$repositories = [];

foreach ((new Finder)->in($directory)->files() as $repository) {
foreach ((new Finder())->in($directory)->files() as $repository) {
$repository = $namespace.str_replace(
['/', '.php'],
['\\', ''],
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Search/RepositorySearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ protected function applyFilters(RestifyRequest $request, Repository $repository,

public static function make(): static
{
return new static;
return new static();
}
}
2 changes: 1 addition & 1 deletion src/Traits/AuthorizableModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,6 @@ public function authorizedTo(Request $request, $ability)
*/
public static function isRepositoryContext()
{
return new static instanceof Repository;
return new static() instanceof Repository;
}
}
2 changes: 1 addition & 1 deletion src/Traits/AuthorizesRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function auth($callback)
{
static::$authUsing = $callback;

return new static;
return new static();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/InteractWithSQLight.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function resolveConnection($connection = null)

public static function bootSushi()
{
$instance = (new static);
$instance = (new static());
$cacheFileName = 'sushi-'.Str::kebab(str_replace('\\', '', static::class)).'.sqlite';
$cacheDirectory = realpath(config('sushi.cache-path', storage_path('framework/cache')));
$cachePath = $cacheDirectory.'/'.$cacheFileName;
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/InteractWithSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static function collectFilters($type): Collection

return $type instanceof Filter
? tap($type, fn ($filter) => $filter->column = $filter->column ?? $column)
: tap(new $base, function (Filter $filter) use ($column, $type) {
: tap(new $base(), function (Filter $filter) use ($column, $type) {
$filter->type = $type ? $type : 'value';
$filter->column = $column;
});
Expand Down
Loading