Skip to content

Commit 88a47ed

Browse files
authored
Merge pull request #9 from mtawil/support-laravel-10
Support laravel 10
2 parents 15080a9 + 9164f6c commit 88a47ed

19 files changed

+79
-126
lines changed

composer.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^8.0",
20-
"spatie/laravel-package-tools": "^1.4.3",
21-
"illuminate/contracts": "^8.37|^v9.0.0",
22-
"illuminate/support": "^5.8|^6.0|^7.0|^8.0|^9.0",
19+
"php": "^8.0|^8.1|^8.2",
20+
"spatie/laravel-package-tools": "^1.4",
21+
"illuminate/contracts": "^8.0|^v9.0|^v10.0",
22+
"illuminate/support": "^8.0|^9.0|^10.0",
2323
"laravel/tinker": "^1.0|^2.0"
2424
},
2525
"require-dev": {
26-
"brianium/paratest": "^6.2",
27-
"nunomaduro/collision": "^5.3",
28-
"orchestra/testbench": "^6.15",
29-
"phpunit/phpunit": "^9.3",
30-
"spatie/laravel-ray": "^1.20",
31-
"vimeo/psalm": "^4.4"
26+
"brianium/paratest": "^6.2|^7.0",
27+
"nunomaduro/collision": "^5.3|^6.0|^7.0",
28+
"orchestra/testbench": "^6.15|^7.0|^8.0",
29+
"phpunit/phpunit": "^9.3|^10.0",
30+
"spatie/laravel-ray": "^1.2",
31+
"vimeo/psalm": "^4.4|^5.0"
3232
},
3333
"autoload": {
3434
"psr-4": {

config/model-stats.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
|
1717
*/
1818

19-
'enabled' => env('MODEL_STATS_ENABLED', true),
20-
'allow_custom_code' => env('MODEL_STATS_CUSTOM_CODE', false),
19+
'enabled' => env('MODEL_STATS_ENABLED', true),
20+
'allow_custom_code' => env('MODEL_STATS_CUSTOM_CODE', false),
2121

2222
/*
2323
|--------------------------------------------------------------------------
@@ -29,7 +29,7 @@
2929
| the existing middleware. Or, you can simply stick with this list.
3030
|
3131
*/
32-
'middleware' => [
32+
'middleware' => [
3333
'web',
3434
\Jhumanj\LaravelModelStats\Http\Middleware\Authorize::class,
3535
],
@@ -43,7 +43,7 @@
4343
| this configures the table name based on your connection.
4444
|
4545
*/
46-
'table_name' => 'model_stats_dashboards',
46+
'table_name' => 'model_stats_dashboards',
4747

4848
/*
4949
|--------------------------------------------------------------------------
@@ -54,7 +54,7 @@
5454
| This can be used to ensure a read-only connection, by using a custom connection with a read-only user.
5555
|
5656
*/
57-
'query_database_connection' => env('MODEL_STATS_DB_CONNECTION', env('DB_CONNECTION')),
57+
'query_database_connection' => env('MODEL_STATS_DB_CONNECTION', env('DB_CONNECTION')),
5858

5959
/*
6060
|--------------------------------------------------------------------------
@@ -65,6 +65,6 @@
6565
| be starting the '/stats' prefix, and names will start with 'stats.'.
6666
|
6767
*/
68-
'routes_prefix' => 'stats',
68+
'routes_prefix' => 'stats',
6969
'route_names_prefix' => 'stats.',
7070
];

database/factories/DashboardFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Jhumanj\LaravelModelStats\Database\Factories;
44

5-
use Jhumanj\LaravelModelStats\Models\Dashboard;
65
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Jhumanj\LaravelModelStats\Models\Dashboard;
77

88
class DashboardFactory extends Factory
99
{
@@ -12,9 +12,9 @@ class DashboardFactory extends Factory
1212
public function definition(): array
1313
{
1414
return [
15-
'name' => $this->faker->name,
15+
'name' => $this->faker->name,
1616
'description' => $this->faker->sentence,
17-
'body' => '{"widgets":[]}',
17+
'body' => '{"widgets":[]}',
1818
];
1919
}
2020
}

database/migrations/create_model-stats_table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

3-
use Illuminate\Support\Facades\Config;
43
use Illuminate\Database\Migrations\Migration;
54
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Config;
66
use Illuminate\Support\Facades\Schema;
77

8-
return new class extends Migration {
9-
8+
return new class() extends Migration
9+
{
1010
public function up(): void
1111
{
1212
Schema::create(Config::get('model-stats.table_name'), function (Blueprint $table) {

phpunit.xml.dist

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5-
backupGlobals="false"
6-
backupStaticAttributes="false"
7-
bootstrap="vendor/autoload.php"
8-
colors="true"
9-
convertErrorsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertWarningsToExceptions="true"
12-
processIsolation="false"
13-
stopOnFailure="false"
14-
executionOrder="random"
15-
failOnWarning="true"
16-
failOnRisky="true"
17-
failOnEmptyTestSuite="true"
18-
beStrictAboutOutputDuringTests="true"
19-
verbose="true"
20-
>
21-
<testsuites>
22-
<testsuite name="Jhumanj Test Suite">
23-
<directory>tests</directory>
24-
</testsuite>
25-
</testsuites>
26-
<coverage>
27-
<include>
28-
<directory suffix=".php">./src</directory>
29-
</include>
30-
<report>
31-
<html outputDirectory="build/coverage"/>
32-
<text outputFile="build/coverage.txt"/>
33-
<clover outputFile="build/logs/clover.xml"/>
34-
</report>
35-
</coverage>
36-
<logging>
37-
<junit outputFile="build/report.junit.xml"/>
38-
</logging>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="Jhumanj Test Suite">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<coverage>
9+
<report>
10+
<html outputDirectory="build/coverage"/>
11+
<text outputFile="build/coverage.txt"/>
12+
<clover outputFile="build/logs/clover.xml"/>
13+
</report>
14+
</coverage>
15+
<logging>
16+
<junit outputFile="build/report.junit.xml"/>
17+
</logging>
18+
<source>
19+
<include>
20+
<directory suffix=".php">./src</directory>
21+
</include>
22+
</source>
3923
</phpunit>

routes/web.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88

99
Route::prefix('api')->name('api.')->group(function () {
1010
Route::apiResource('dashboards', \Jhumanj\LaravelModelStats\Http\Controllers\DashboardController::class);
11-
Route::post('widgets/data',
12-
[\Jhumanj\LaravelModelStats\Http\Controllers\StatController::class, 'widgetData']);
13-
Route::post('widgets/custom-code/data',
14-
[\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'widgetData']);
11+
Route::post(
12+
'widgets/data',
13+
[\Jhumanj\LaravelModelStats\Http\Controllers\StatController::class, 'widgetData']
14+
);
15+
Route::post(
16+
'widgets/custom-code/data',
17+
[\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'widgetData']
18+
);
1519

16-
Route::post('widgets/custom-code/execute',
17-
[\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'executeCustomCode']);
20+
Route::post(
21+
'widgets/custom-code/execute',
22+
[\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'executeCustomCode']
23+
);
1824
});
1925

2026
Route::get('/{view?}', [\Jhumanj\LaravelModelStats\Http\Controllers\HomeController::class, 'home'])

src/AuthorizesRequests.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,24 @@ trait AuthorizesRequests
99
{
1010
/**
1111
* The callback that should be used to authenticate ModelStats users.
12-
*
13-
* @var \Closure
1412
*/
1513
public static Closure $authUsing;
1614

1715
/**
1816
* Register the ModelStats authentication callback.
19-
*
20-
* @param \Closure $callback
21-
*
22-
* @return static
2317
*/
2418
public static function auth(Closure $callback): static
2519
{
2620
static::$authUsing = $callback;
2721

28-
return new static;
22+
return new static();
2923
}
3024

3125
/**
3226
* Determine if the given request can access the ModelStats dashboard.
33-
*
34-
* @param \Illuminate\Http\Request $request
35-
*
36-
* @return bool
3727
*/
3828
public static function check(Request $request): bool
3929
{
40-
return (static::$authUsing ?: fn () => app()->environment('local'))($request);
30+
return (static::$authUsing)($request);
4131
}
4232
}

src/Console/InstallModelStatsPackage.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
namespace Jhumanj\LaravelModelStats\Console;
54

65
use Illuminate\Console\Command;
@@ -32,8 +31,6 @@ public function handle(): void
3231

3332
/**
3433
* Register the ModelStats service provider in the application configuration file.
35-
*
36-
* @return void
3734
*/
3835
private function registerModelStatsServiceProvider(): void
3936
{

src/Http/Controllers/DashboardController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function destroy(Dashboard $dashboard): JsonResponse
3939
$dashboard->delete();
4040

4141
return $this->success([
42-
'message' => 'Dashboard deleted',
42+
'message' => 'Dashboard deleted',
4343
]);
4444
}
4545
}

src/Http/Controllers/HomeController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
namespace Jhumanj\LaravelModelStats\Http\Controllers;
44

5-
use Illuminate\Container\Container;
65
use Illuminate\Contracts\Foundation\Application;
76
use Illuminate\Contracts\View\Factory;
87
use Illuminate\Contracts\View\View;
98
use Illuminate\Database\Eloquent\Model;
109
use Illuminate\Support\Collection;
1110
use Illuminate\Support\Facades\File;
11+
use Illuminate\Support\Facades\Schema;
1212
use ReflectionClass;
13-
use Schema;
1413

1514
class HomeController extends Controller
1615
{
@@ -41,7 +40,7 @@ private function getModels(): Collection
4140

4241
return sprintf(
4342
'\%s%s',
44-
Container::getInstance()->getNamespace(),
43+
app()->getNamespace(),
4544
strtr(substr($path, 0, strrpos($path, '.')), '/', '\\')
4645
);
4746
})
@@ -57,7 +56,6 @@ private function getModels(): Collection
5756
return $valid;
5857
});
5958

60-
6159
return $models->map(fn (string $class) => [
6260
'class' => $class,
6361
'fields' => $this->getClassFields($class),
@@ -66,6 +64,6 @@ private function getModels(): Collection
6664

6765
private function getClassFields(string $class)
6866
{
69-
return Schema::getColumnListing((new $class)->getTable());
67+
return Schema::getColumnListing((new $class())->getTable());
7068
}
7169
}

src/Http/Middleware/Authorize.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ class Authorize
99
/**
1010
* Handle the incoming request.
1111
*
12-
* @param \Illuminate\Http\Request $request
13-
* @param \Closure $next
14-
*
12+
* @param \Illuminate\Http\Request $request
13+
* @param \Closure $next
1514
* @return \Illuminate\Http\Response
1615
*/
1716
public function handle($request, $next)

src/Http/Middleware/CustomCodeEnabled.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
<?php
22

3-
43
namespace Jhumanj\LaravelModelStats\Http\Middleware;
54

65
class CustomCodeEnabled
76
{
87
/**
98
* Handle the incoming request.
109
*
11-
* @param \Illuminate\Http\Request $request
12-
* @param \Closure $next
13-
*
14-
* @return \Illuminate\Http\Response
10+
* @param \Illuminate\Http\Request $request
11+
* @param \Closure $next
12+
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
1513
*/
1614
public function handle($request, $next)
1715
{

src/Http/Requests/Dashboard/StoreRequest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ class StoreRequest extends FormRequest
88
{
99
/**
1010
* Get the validation rules that apply to the request.
11-
*
12-
* @return array
1311
*/
1412
public function rules(): array
1513
{

src/Http/Requests/Dashboard/UpdateRequest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ class UpdateRequest extends FormRequest
88
{
99
/**
1010
* Get the validation rules that apply to the request.
11-
*
12-
* @return array
1311
*/
1412
public function rules(): array
1513
{

src/Http/Requests/Widgets/DataRequest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Jhumanj\LaravelModelStats\Http\Requests\Widgets;
44

5-
use Illuminate\Container\Container;
65
use Illuminate\Database\Eloquent\Model;
76
use Illuminate\Foundation\Http\FormRequest;
87
use Illuminate\Support\Collection;
@@ -32,8 +31,6 @@ class DataRequest extends FormRequest
3231

3332
/**
3433
* Get the validation rules that apply to the request.
35-
*
36-
* @return array
3734
*/
3835
public function rules(): array
3936
{
@@ -53,15 +50,18 @@ private function getModels(): Collection
5350
->map(function ($item) {
5451
$path = $item->getRelativePathName();
5552

56-
return sprintf('\%s%s', Container::getInstance()
57-
->getNamespace(), strtr(substr($path, 0, strrpos($path, '.')), '/', '\\'));
53+
return sprintf(
54+
'\%s%s',
55+
app()->getNamespace(),
56+
strtr(substr($path, 0, strrpos($path, '.')), '/', '\\')
57+
);
5858
})->filter(function ($class) {
5959
$valid = false;
6060

6161
if (class_exists($class)) {
6262
$reflection = new \ReflectionClass($class);
6363
$valid = $reflection->isSubclassOf(Model::class)
64-
&& ! $reflection->isAbstract();
64+
&& ! $reflection->isAbstract();
6565
}
6666

6767
return $valid;

0 commit comments

Comments
 (0)