Skip to content

Commit 4f65a2c

Browse files
Quentin SchmickalbanhJamesFreeman
authored
Laravel 9 (#314)
* Updated to allow Laravel 9 usage; Updated CI to do a matrix of versions * Updated typing * Laravel 9 tests and styling fixed (#327) * allow constraints * fix contract break * reverted types to get tests to pass * remove unneeded element Co-authored-by: James Freeman <[email protected]> * Laravel 9 style fixes (#330) * Handle null is_active Co-authored-by: Alban Horrocks <[email protected]> Co-authored-by: James Freeman <[email protected]>
1 parent 60cb88f commit 4f65a2c

37 files changed

+225
-177
lines changed

.github/workflows/laravel.yml

+23-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,37 @@ on: [push, pull_request]
44

55
jobs:
66
laravel-tests:
7-
runs-on: ubuntu-latest
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
os: [ ubuntu-latest ]
12+
php: [ 8.0, 8.1 ]
13+
laravel: [ 9.* ]
14+
stability: [ prefer-stable ]
15+
include:
16+
- laravel: 9.*
17+
testbench: ^7.0
18+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
19+
820
steps:
921
- uses: actions/checkout@v2
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.php }}
26+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
27+
coverage: none
1028
- name: Cache dependencies
1129
uses: actions/cache@v2
1230
with:
1331
path: ~/.composer/cache/files
1432
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
1533
restore-keys: |
1634
${{ runner.os }}-composer-
17-
- name: Install Dependencies
18-
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
35+
- name: Install dependencies
36+
run: |
37+
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
38+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
1939
- name: Execute tests (Unit and Feature tests) via PHPUnit
2040
run: vendor/bin/phpunit

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ _ide_helper.php
66
.DS_Store
77
.idea
88
*.sketch
9+
.phpunit.result.cache

composer.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=7.3",
19+
"php": "^8.0.0|^8.1.0",
2020
"ext-json": "*",
2121
"doctrine/dbal": "^3.1",
22-
"illuminate/bus": "^8.11",
23-
"illuminate/console": "^8.11",
24-
"illuminate/contracts": "^8.11",
25-
"illuminate/database": "^8.11",
26-
"illuminate/events": "^8.11",
27-
"illuminate/notifications": "^8.11",
22+
"illuminate/bus": "^8.11|^9.0",
23+
"illuminate/console": "^8.11|^9.0",
24+
"illuminate/contracts": "^8.11|^9.0",
25+
"illuminate/database": "^8.11|^9.0",
26+
"illuminate/events": "^8.11|^9.0",
27+
"illuminate/notifications": "^8.11|^9.0",
2828
"laravelcollective/html": "^6.0"
2929
},
3030
"require-dev": {
3131
"mockery/mockery": "^1.0",
32-
"orchestra/database": "^6.0",
33-
"orchestra/testbench" : "^6.0",
32+
"orchestra/database": "^6.0|^7.0",
33+
"orchestra/testbench" : "^6.0|^7.0",
3434
"phpunit/phpunit": "^9.0"
3535
},
3636
"suggest": {

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
- totem
1515

1616
db:
17-
image: mysql:8.0.20
17+
image: mysql/mysql-server:8.0.27
1818
container_name: totem-db
1919
restart: unless-stopped
2020
environment:

docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:7.3.29-fpm
1+
FROM arm64v8/php:8.1.0-fpm
22

33
# Install system dependencies
44
RUN apt-get update && apt-get install -y \

src/Contracts/TaskInterface.php

+23-19
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,71 @@
22

33
namespace Studio\Totem\Contracts;
44

5+
use Illuminate\Database\Eloquent\Builder;
6+
use Illuminate\Database\Eloquent\Collection;
7+
use Studio\Totem\Task;
8+
59
interface TaskInterface
610
{
711
/**
812
* Returns Eloquent Builder.
913
*
10-
* @return \Illuminate\Database\Eloquent\Builder
14+
* @return Builder
1115
*/
12-
public function builder();
16+
public function builder(): Builder;
1317

1418
/**
1519
* Returns a task by its primary key.
1620
*
17-
* @param int|\Studio\Totem\Task $id
18-
* @return \Studio\Totem\Task
21+
* @param int|Task $id
22+
* @return Task
1923
*/
20-
public function find($id);
24+
public function find(Task|int $id);
2125

2226
/**
2327
* Returns all tasks.
2428
*
25-
* @return \Illuminate\Database\Eloquent\Collection
29+
* @return Collection
2630
*/
27-
public function findAll();
31+
public function findAll(): Collection;
2832

2933
/**
3034
* Returns all active tasks.
3135
*
32-
* @return \Illuminate\Database\Eloquent\Collection
36+
* @return Collection
3337
*/
34-
public function findAllActive();
38+
public function findAllActive(): Collection;
3539

3640
/**
3741
* Creates a new task with the given data.
3842
*
3943
* @param array $input
40-
* @return \Studio\Totem\Task
44+
* @return Task|bool
4145
*/
42-
public function store(array $input);
46+
public function store(array $input): Task|bool;
4347

4448
/**
4549
* Updates the given task with the given data.
4650
*
4751
* @param array $input
48-
* @param \Studio\Totem\Task $task
49-
* @return \Studio\Totem\Task
52+
* @param Task $task
53+
* @return Task
5054
*/
51-
public function update(array $input, $task);
55+
public function update(array $input, Task $task): Task;
5256

5357
/**
5458
* Deletes the given task.
5559
*
56-
* @param int|\Studio\Totem\Task $id
60+
* @param int|Task $id
5761
* @return bool
5862
*/
59-
public function destroy($id);
63+
public function destroy(Task|int $id): bool;
6064

6165
/**
6266
* Executes the given task.
6367
*
64-
* @param int|\Studio\Totem\Task $id
65-
* @return bool
68+
* @param int|Task $id
69+
* @return Task
6670
*/
67-
public function execute($id);
71+
public function execute(Task|int $id): Task;
6872
}

src/Events/BroadcastingEvent.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class BroadcastingEvent extends TaskEvent implements ShouldBroadcast
1313
/**
1414
* Get the channels the event should broadcast on.
1515
*
16-
* @return \Illuminate\Broadcasting\Channel|\Illuminate\Broadcasting\Channel[]|PrivateChannel
16+
* @return PrivateChannel
1717
*/
18-
public function broadcastOn()
18+
public function broadcastOn(): PrivateChannel
1919
{
2020
return new PrivateChannel(config('totem.broadcasting.channel'));
2121
}
@@ -25,7 +25,7 @@ public function broadcastOn()
2525
*
2626
* @return bool
2727
*/
28-
public function broadcastWhen()
28+
public function broadcastWhen(): bool
2929
{
3030
return config('totem.broadcasting.enabled');
3131
}

src/Events/Creating.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Studio\Totem\Events;
44

5-
use Illuminate\Broadcasting\Channel;
65
use Illuminate\Broadcasting\InteractsWithSockets;
76
use Illuminate\Broadcasting\PrivateChannel;
87
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
@@ -16,7 +15,7 @@ class Creating implements ShouldBroadcast
1615
/**
1716
* @var array
1817
*/
19-
private $input;
18+
private array $input;
2019

2120
/**
2221
* Create a new event instance.
@@ -31,9 +30,9 @@ public function __construct(array $input)
3130
/**
3231
* Get the channels the event should broadcast on.
3332
*
34-
* @return Channel|array
33+
* @return PrivateChannel
3534
*/
36-
public function broadcastOn()
35+
public function broadcastOn(): PrivateChannel
3736
{
3837
return new PrivateChannel('channel-name');
3938
}

src/Events/Deleted.php

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ class Deleted extends Event
66
{
77
/**
88
* Create a new event instance.
9-
*
10-
* @param array $input
11-
* @param Task $task
129
*/
1310
public function __construct()
1411
{

src/Events/Executed.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Executed extends BroadcastingEvent
1111
* Executed constructor.
1212
*
1313
* @param Task $task
14-
* @param string $started
14+
* @param string|float|int $started
15+
* @param $output
1516
*/
1617
public function __construct(Task $task, $started, $output)
1718
{

src/Events/TaskEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TaskEvent extends Event
1313
/**
1414
* @var Task
1515
*/
16-
public $task;
16+
public Task $task;
1717

1818
/**
1919
* Constructor.

src/Events/Updating.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Studio\Totem\Events;
44

5-
use Illuminate\Broadcasting\Channel;
65
use Illuminate\Broadcasting\PrivateChannel;
76
use Studio\Totem\Task;
87

@@ -11,7 +10,7 @@ class Updating extends BroadcastingEvent
1110
/**
1211
* @var array
1312
*/
14-
private $input;
13+
private array $input;
1514

1615
/**
1716
* Create a new event instance.
@@ -28,9 +27,9 @@ public function __construct(array $input, Task $task)
2827
/**
2928
* Get the channels the event should broadcast on.
3029
*
31-
* @return Channel|array
30+
* @return PrivateChannel
3231
*/
33-
public function broadcastOn()
32+
public function broadcastOn(): PrivateChannel
3433
{
3534
return new PrivateChannel('channel-name');
3635
}

src/Frequency.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Studio\Totem;
44

5+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
56
use Studio\Totem\Traits\HasParameters;
67

78
class Frequency extends TotemModel
@@ -17,9 +18,9 @@ class Frequency extends TotemModel
1718
];
1819

1920
/**
20-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
21+
* @return BelongsTo
2122
*/
22-
public function task()
23+
public function task(): BelongsTo
2324
{
2425
return $this->belongsTo(Task::class);
2526
}

src/Http/Controllers/ActiveTasksController.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Studio\Totem\Http\Controllers;
44

5+
use Illuminate\Http\JsonResponse;
56
use Illuminate\Http\Request;
67
use Studio\Totem\Contracts\TaskInterface;
78

@@ -10,7 +11,7 @@ class ActiveTasksController extends Controller
1011
/**
1112
* @var TaskInterface
1213
*/
13-
private $tasks;
14+
private TaskInterface $tasks;
1415

1516
/**
1617
* @param TaskInterface $tasks
@@ -25,10 +26,10 @@ public function __construct(TaskInterface $tasks)
2526
/**
2627
* Store a newly active task in storage.
2728
*
28-
* @param \Illuminate\Http\Request $request
29-
* @return \Illuminate\Http\Response
29+
* @param Request $request
30+
* @return JsonResponse
3031
*/
31-
public function store(Request $request)
32+
public function store(Request $request): JsonResponse
3233
{
3334
$task = $this->tasks->activate($request->all());
3435

@@ -39,9 +40,9 @@ public function store(Request $request)
3940
* Remove the specified resource from storage.
4041
*
4142
* @param int $id
42-
* @return \Illuminate\Http\Response
43+
* @return JsonResponse
4344
*/
44-
public function destroy($id)
45+
public function destroy(int $id): JsonResponse
4546
{
4647
$task = $this->tasks->deactivate($id);
4748

src/Http/Controllers/DashboardController.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
namespace Studio\Totem\Http\Controllers;
44

5+
use Illuminate\Http\RedirectResponse;
6+
57
class DashboardController extends Controller
68
{
79
/**
810
* Single page application catch-all route.
911
*
10-
* @return \Illuminate\Http\Response
12+
* @return RedirectResponse
1113
*/
12-
public function index()
14+
public function index(): RedirectResponse
1315
{
1416
return redirect()->route('totem.tasks.all');
1517
}

src/Http/Controllers/ExecuteTasksController.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ class ExecuteTasksController extends Controller
1010
/**
1111
* @var TaskInterface
1212
*/
13-
private $tasks;
13+
private TaskInterface $tasks;
1414

1515
/**
1616
* @param TaskInterface $tasks
1717
*/
1818
public function __construct(TaskInterface $tasks)
1919
{
20+
parent::__construct();
21+
2022
$this->tasks = $tasks;
2123
}
2224

0 commit comments

Comments
 (0)