Skip to content

Commit 9d8e43d

Browse files
committed
Apply property types
1 parent a16ca92 commit 9d8e43d

File tree

8 files changed

+30
-48
lines changed

8 files changed

+30
-48
lines changed

UPGRADING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
> Note: This is a complete refactor! Please be sure to read the docs carefully before upgrading.
77
8+
* Minimum PHP version has been bumped to `7.4` to match the upcoming framework changes
9+
* All properties that can be typed have been
810
* The services no longer exist; remove all references to `Services::Assets` and `Services::manifests` to avoid exceptions
911
* This library no longer publishes Assets; convert Manifests to the framework's new [Publisher format](https://codeigniter.com/user_guide/libraries/publisher.html)
1012
* Many of the example Manifests now have an official Publisher equivalent at [Tatter\Frontend](https://github.com/tattersoftware/codeigniter4-frontend)

src/Bundle.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,35 @@ abstract class Bundle
2323
*
2424
* @var Asset[]
2525
*/
26-
protected $assets = [];
26+
protected array $assets = [];
2727

2828
/**
2929
* Bundle classes to merge with this Bundle.
3030
*
3131
* @var string[]
3232
*/
33-
protected $bundles = [];
33+
protected array $bundles = [];
3434

3535
/**
3636
* Paths to include in this Bundle.
3737
*
3838
* @var string[]
3939
*/
40-
protected $paths = [];
40+
protected array $paths = [];
4141

4242
/**
4343
* URIs to include in this Bundle.
4444
*
4545
* @var string[]
4646
*/
47-
protected $uris = [];
47+
protected array $uris = [];
4848

4949
/**
5050
* Strings to include in this Bundle.
5151
*
5252
* @var string[]
5353
*/
54-
protected $strings = [];
54+
protected array $strings = [];
5555

5656
//--------------------------------------------------------------------
5757
// Asset Handling

src/Config/Assets.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,32 @@ class Assets extends BaseConfig
1414

1515
/**
1616
* Asset URI base, relative to baseURL.
17-
*
18-
* @var string
1917
*/
20-
public $uri = 'assets/';
18+
public string $uri = 'assets/';
2119

2220
/**
2321
* Asset storage location in the filesystem.
2422
* Must be somewhere web accessible.
25-
*
26-
* @var string
2723
*/
28-
public $directory = FCPATH . 'assets/';
24+
public string $directory = FCPATH . 'assets/';
2925

3026
/**
3127
* Path for third-party published Assets. The path is relative to
3228
* both $directory and $uri. Recommended to add the resulting file
3329
* path to .gitignore so published vendor assets will not be tracked.
34-
*
35-
* @var string
3630
*/
37-
public $vendor = 'vendor/';
31+
public string $vendor = 'vendor/';
3832

3933
/**
4034
* Whether to append file modification timestamps on asset tags.
4135
* Makes it less likely for modified assets to remain cached.
42-
*
43-
* @var bool
4436
*/
45-
public $useTimestamps = true;
37+
public bool $useTimestamps = true;
4638

4739
/**
4840
* Whether to cache bundles for faster route responses.
49-
*
50-
* @var bool
5141
*/
52-
public $useCache = ENVIRONMENT === 'production';
42+
public bool $useCache = ENVIRONMENT === 'production';
5343

5444
//--------------------------------------------------------------------
5545
// Route Assets
@@ -77,7 +67,7 @@ class Assets extends BaseConfig
7767
*
7868
* @var array<string,string[]>
7969
*/
80-
public $routes = [];
70+
public array $routes = [];
8171

8272
/**
8373
* Gathers Assets and Bundles that match the relative URI path.

src/Test/AssetsTestTrait.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,15 @@ trait AssetsTestTrait
1818
{
1919
/**
2020
* The virtual workspace.
21-
*
22-
* @var vfsStreamDirectory|null
2321
*/
24-
protected static $root;
22+
protected static ?vfsStreamDirectory $root = null;
2523

2624
/**
2725
* Whether the publishers have been run.
28-
*
29-
* @var bool
3026
*/
31-
private static $published = false;
27+
private static bool $published = false;
3228

33-
/**
34-
* @var AssetsConfig
35-
*/
36-
protected $assets;
29+
protected AssetsConfig $assets;
3730

3831
/**
3932
* Creates the VFS (if necessary) and updates the Assets config.

tests/BundleTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ final class BundleTest extends TestCase
1212
{
1313
public function testConstructorPaths()
1414
{
15-
$bundle = new class () extends Bundle {
16-
protected $paths = ['apple.css'];
15+
$bundle = new class () extends Bundle {
16+
protected array $paths = ['apple.css'];
1717
};
1818

1919
$assets = $bundle->getAssets();
@@ -25,8 +25,8 @@ public function testConstructorPaths()
2525

2626
public function testConstructorBundles()
2727
{
28-
$bundle = new class () extends Bundle {
29-
protected $bundles = [FruitSalad::class];
28+
$bundle = new class () extends Bundle {
29+
protected array $bundles = [FruitSalad::class];
3030
};
3131

3232
$assets = $bundle->getAssets();
@@ -38,8 +38,8 @@ public function testConstructorBundles()
3838

3939
public function testConstructorStrings()
4040
{
41-
$bundle = new class () extends Bundle {
42-
protected $strings = ['foobar'];
41+
$bundle = new class () extends Bundle {
42+
protected array $strings = ['foobar'];
4343
};
4444

4545
$assets = $bundle->getAssets();
@@ -51,17 +51,17 @@ public function testConstructorStrings()
5151

5252
public function testStringable()
5353
{
54-
$asset = new class () extends Bundle {
55-
protected $paths = ['apple.css'];
54+
$asset = new class () extends Bundle {
55+
protected array $paths = ['apple.css'];
5656
};
5757

5858
$this->assertSame('<link href="https://example.com/assets/apple.css" rel="stylesheet" type="text/css" />', (string) $asset);
5959
}
6060

6161
public function testHead()
6262
{
63-
$asset = new class () extends Bundle {
64-
protected $paths = [
63+
$asset = new class () extends Bundle {
64+
protected array $paths = [
6565
'apple.css',
6666
'banana.js',
6767
];

tests/_support/Bundles/FruitSalad.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FruitSalad extends Bundle
1111
*
1212
* @var string[]
1313
*/
14-
protected $paths = [
14+
protected array $paths = [
1515
'apple.css',
1616
'banana.js',
1717
];

tests/_support/Bundles/LunchBreak.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class LunchBreak extends Bundle
1111
*
1212
* @var string[]
1313
*/
14-
protected $paths = [
14+
protected array $paths = [
1515
'banana.js',
1616
'directory/machines.js',
1717
];
@@ -21,7 +21,7 @@ class LunchBreak extends Bundle
2121
*
2222
* @var string[]
2323
*/
24-
protected $uris = [
24+
protected array $uris = [
2525
'https://water.com/glassof.css',
2626
];
2727
}

tests/_support/TestCase.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
abstract class TestCase extends CIUnitTestCase
1010
{
11-
/**
12-
* @var AssetsConfig
13-
*/
14-
protected $assets;
11+
protected AssetsConfig $assets;
1512

1613
/**
1714
* Preps the config for the test directory.

0 commit comments

Comments
 (0)