Skip to content

Commit

Permalink
The code has been refactored to align with modern PHP standards.
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Nov 10, 2024
1 parent 9900525 commit 373b79c
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/Metrics/Chartable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function scopeCountForGroup(Builder $builder, string $groupColumn): Group
*/
private function groupByDays(Builder $builder, string $value, $startDate = null, $stopDate = null, ?string $dateColumn = null): TimeCollection
{
$dateColumn = $dateColumn ?? $builder->getModel()->getCreatedAtColumn();
$dateColumn ??= $builder->getModel()->getCreatedAtColumn();

$startDate = empty($startDate)
? Carbon::now()->subMonth()
Expand Down
2 changes: 1 addition & 1 deletion src/Metrics/GroupCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GroupCollection extends Collection
public function toChart(?\Closure $closure = null): array
{
// If the closure is not set, we define a default one that returns the original label.
$closure = $closure ?? static fn ($label) => $label;
$closure ??= static fn ($label) => $label;

return $this
->sortByDesc('value')
Expand Down
6 changes: 2 additions & 4 deletions src/Metrics/TimeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function makeFromKeyValue($values, string $format = 'Y-m-d'): TimeCollect
*/
public function toChart(string $name, ?\Closure $closure = null): array
{
$closure = $closure ?? static fn ($label) => $label;
$closure ??= static fn ($label) => $label;

return [
'name' => $name,
Expand Down Expand Up @@ -94,8 +94,6 @@ public function transformLabel(callable $callback): TimeCollection
*/
public function withoutZeroValues(): TimeCollection
{
return $this->filter(function (array $item) {
return $item['value'] !== 0;
});
return $this->filter(fn (array $item) => $item['value'] !== 0);
}
}
36 changes: 21 additions & 15 deletions src/Platform/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,30 @@ private function replaceInFiles(string $directory, string $search, string $repla
return $this;
}

$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory));
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($directory)
);

// Проходим по всем файлам в директории
// Iterate through all files in the directory
foreach ($files as $file) {
// Проверяем, что это файл и имеет расширение .php
if ($file->isFile() && $file->getExtension() === 'php') {
$filePath = $file->getRealPath();
$fileContents = file_get_contents($filePath);

// Если содержимое файла содержит старый namespace
if (strpos($fileContents, $search) !== false) {
// Заменяем старый namespace на новый
$updatedContents = str_replace($search, $replace, $fileContents);

// Сохраняем изменения
file_put_contents($filePath, $updatedContents);
}
// Skip if not a .php file
if ($file->getExtension() !== 'php') {
continue;
}

$filePath = $file->getRealPath();
$fileContents = file_get_contents($filePath);

// Skip if the file does not contain the old namespace
if (! str_contains($fileContents, $search)) {
continue;
}

// Replace the old namespace with the new one
$updatedContents = str_replace($search, $replace, $fileContents);

// Save the changes
file_put_contents($filePath, $updatedContents);
}

return $this;
Expand Down
10 changes: 1 addition & 9 deletions src/Platform/Events/AddRoleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ class AddRoleEvent
{
use SerializesModels;

/**
* The authenticated user.
*
* @var User
*/
public $user;

/**
* The role(s) that were added to the user.
*
Expand All @@ -35,9 +28,8 @@ class AddRoleEvent
* @param mixed $user The user to whom the role(s) is added
* @param mixed $role The role(s) to be added
*/
public function __construct($user, $role)
public function __construct(public mixed $user, mixed $role)
{
$this->user = $user;
$this->roles = collect($role);
}
}
8 changes: 1 addition & 7 deletions src/Platform/Events/InstallEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@
*/
class InstallEvent
{
/**
* @var Command
*/
public $command;

/**
* InstallEvent constructor.
*/
public function __construct(Command $command)
public function __construct(public Command $command)
{
$this->command = $command;
}
}
11 changes: 1 addition & 10 deletions src/Platform/Events/RemoveRoleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@

use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
use Orchid\Platform\Models\User;

class RemoveRoleEvent
{
use SerializesModels;

/**
* The authenticated user.
*
* @var User
*/
public $user;

/**
* Roles that will be removed.
*
Expand All @@ -32,9 +24,8 @@ class RemoveRoleEvent
* @param mixed $user The user object this event relates to.
* @param mixed $role The role(s) to remove. Can accept either a Collection or an array.
*/
public function __construct($user, $role)
public function __construct(public mixed $user, mixed $role)
{
$this->user = $user;
$this->roles = collect($role);
}
}
16 changes: 1 addition & 15 deletions src/Platform/Events/ReplicateFileEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,10 @@ class ReplicateFileEvent
{
use SerializesModels;

/**
* @var Attachment
*/
public $attachment;

/**
* The timestamp when the event occurred.
*
* @var int
*/
public $time;

/**
* ReplicateFileEvent constructor.
*/
public function __construct(Attachment $attachment, int $time)
public function __construct(public Attachment $attachment, public int $time)
{
$this->attachment = $attachment;
$this->time = $time;
}
}
8 changes: 1 addition & 7 deletions src/Platform/Events/UploadedFileEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ class UploadedFileEvent
{
use SerializesModels;

/**
* @var Attachment
*/
public $attachment;

/**
* UploadedFileEvent constructor.
*/
public function __construct(Attachment $attachment)
public function __construct(public Attachment $attachment)
{
$this->attachment = $attachment;
}
}

0 comments on commit 373b79c

Please sign in to comment.