Skip to content

Commit

Permalink
Fix psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mtawil committed Aug 24, 2023
1 parent 1d81a35 commit 457efcb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/AuthorizesRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public static function auth(Closure $callback): static
*/
public static function check(Request $request): bool
{
return (static::$authUsing ?: fn () => app()->environment('local'))($request);
return (static::$authUsing)($request);
}
}
7 changes: 3 additions & 4 deletions src/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace Jhumanj\LaravelModelStats\Http\Controllers;

use Illuminate\Container\Container;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
use ReflectionClass;
use Schema;

class HomeController extends Controller
{
Expand Down Expand Up @@ -41,7 +40,7 @@ private function getModels(): Collection

return sprintf(
'\%s%s',
Container::getInstance()->getNamespace(),
app()->getNamespace(),
strtr(substr($path, 0, strrpos($path, '.')), '/', '\\')
);
})
Expand All @@ -51,7 +50,7 @@ private function getModels(): Collection
if (class_exists($class)) {
$reflection = new ReflectionClass($class);
$valid = $reflection->isSubclassOf(Model::class) &&
! $reflection->isAbstract();
!$reflection->isAbstract();
}

return $valid;
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Middleware/CustomCodeEnabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class CustomCodeEnabled
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
*/
public function handle($request, $next)
{
if (! config('model-stats.allow_custom_code')) {
if (!config('model-stats.allow_custom_code')) {
return response([
'message' => 'Custom code not enabled.',
], 403);
Expand Down
10 changes: 6 additions & 4 deletions src/Http/Requests/Widgets/DataRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Jhumanj\LaravelModelStats\Http\Requests\Widgets;

use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -53,15 +52,18 @@ private function getModels(): Collection
->map(function ($item) {
$path = $item->getRelativePathName();

return sprintf('\%s%s', Container::getInstance()
->getNamespace(), strtr(substr($path, 0, strrpos($path, '.')), '/', '\\'));
return sprintf(
'\%s%s',
app()->getNamespace(),
strtr(substr($path, 0, strrpos($path, '.')), '/', '\\')
);
})->filter(function ($class) {
$valid = false;

if (class_exists($class)) {
$reflection = new \ReflectionClass($class);
$valid = $reflection->isSubclassOf(Model::class)
&& ! $reflection->isAbstract();
&& !$reflection->isAbstract();
}

return $valid;
Expand Down
8 changes: 4 additions & 4 deletions src/Services/ModelStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getDailyHistogram(
}

$data = $dataQuery->select([
DB::raw('DATE('.$dateFieldName.') as date'),
DB::raw('DATE(' . $dateFieldName . ') as date'),
DB::raw('COUNT(*) as "count"'),
])->get()->pluck("count", "date");

Expand Down Expand Up @@ -86,7 +86,7 @@ public function getGroupByCount(
DB::table($tableName)->where($dateFieldName, '>=', $from->startOfDay())
->where($dateFieldName, '<=', $to->endOfDay())
->groupBy($aggregateColumn)
->select($aggregateColumn, DB::raw('count(*) as count'))
->select([$aggregateColumn, DB::raw('count(*) as count')])
->get()
->each(function ($row) use (&$mapping, $aggregateColumn) {
$mapping[$row->{$aggregateColumn}] = $row->count;
Expand All @@ -106,11 +106,11 @@ public static function fillMissingDays($data, Carbon $since, Carbon $to, $defaul

foreach (array_reverse(range(0, $daysSince)) as $number) {
$dateKey = $to->copy()->subDays($number)->format('Y-m-d');
if (! isset($data[$dateKey])) {
if (!isset($data[$dateKey])) {
$data[$dateKey] = $defaultValue;
}

if (! is_null($cumulatedSum)) {
if (!is_null($cumulatedSum)) {
$data[$dateKey] += $cumulatedSum;
$cumulatedSum = $data[$dateKey];
}
Expand Down

0 comments on commit 457efcb

Please sign in to comment.