Skip to content

Commit cbabc42

Browse files
committed
Added PHP 8 support; Removed support for PHP 7.1; Added more return types
1 parent 9d2ee4c commit cbabc42

16 files changed

+56
-57
lines changed

.travis.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ language: php
66

77
matrix:
88
include:
9-
# Laravel 5.7.*
10-
- php: 7.1
11-
env: LARAVEL='5.7.*' TESTBENCH='3.7.*' COMPOSER_FLAGS='--prefer-stable' PHP_UNIT_CONFIG='phpunit.xml.old'
12-
- php: 7.2
13-
env: LARAVEL='5.7.*' TESTBENCH='3.7.*' COMPOSER_FLAGS='--prefer-stable' PHP_UNIT_CONFIG='phpunit.xml.old'
149
# Laravel 5.8.*
15-
- php: 7.1
16-
env: LARAVEL='5.8.*' TESTBENCH='3.8.*' COMPOSER_FLAGS='--prefer-stable' PHP_UNIT_CONFIG='phpunit.xml.old'
1710
- php: 7.2
1811
env: LARAVEL='5.8.*' TESTBENCH='3.8.*' COMPOSER_FLAGS='--prefer-stable' PHP_UNIT_CONFIG='phpunit.xml.old'
1912
- php: 7.3
@@ -31,14 +24,14 @@ matrix:
3124
- php: 7.4
3225
env: LARAVEL='7.*' TESTBENCH='5.*' COMPOSER_FLAGS='--prefer-stable' PHP_UNIT_CONFIG='phpunit.xml'
3326
# Laravel 8.*
34-
- php: 7.3
35-
env: LARAVEL='8.*' TESTBENCH='6.*' COMPOSER_FLAGS='--prefer-lowest' PHP_UNIT_CONFIG='phpunit.xml'
3627
- php: 7.3
3728
env: LARAVEL='8.*' TESTBENCH='6.*' COMPOSER_FLAGS='--prefer-stable' PHP_UNIT_CONFIG='phpunit.xml'
3829
- php: 7.4
3930
env: LARAVEL='8.*' TESTBENCH='6.*' COMPOSER_FLAGS='--prefer-lowest' PHP_UNIT_CONFIG='phpunit.xml'
4031
- php: 7.4
4132
env: LARAVEL='8.*' TESTBENCH='6.*' COMPOSER_FLAGS='--prefer-stable' PHP_UNIT_CONFIG='phpunit.xml'
33+
- php: 8.0
34+
env: LARAVEL='8.*' TESTBENCH='6.*' COMPOSER_FLAGS='--prefer-stable' PHP_UNIT_CONFIG='phpunit.xml'
4235
fast_finish: true
4336

4437
before_install:

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "korridor/laravel-computed-attributes",
3-
"description": "Laravel package that adds computed attributes to eloquent models.",
4-
"keywords": ["laravel", "model", "eloquent", "computed", "attribute", "caching", "performance"],
3+
"description": "Laravel package that adds computed attributes to eloquent models. A computed attribute is an accessor were the computed value is saved in the database.",
4+
"keywords": ["laravel", "model", "eloquent", "computed", "attribute", "caching", "performance", "accessor"],
55
"homepage": "https://github.com/korridor/laravel-computed-attributes",
66
"license": "MIT",
77
"authors": [
@@ -12,11 +12,11 @@
1212
],
1313
"minimum-stability": "stable",
1414
"require": {
15-
"php": "^7.1",
15+
"php": "^7.2|^8.0",
1616
"composer/composer": "^1.10 || ^2",
17-
"illuminate/console": "^5.7|^6|^7|^8",
18-
"illuminate/database": "^5.7|^6|^7|^8",
19-
"illuminate/support": "^5.7|^6|^7|^8"
17+
"illuminate/console": "^5.8|^6|^7|^8",
18+
"illuminate/database": "^5.8|^6|^7|^8",
19+
"illuminate/support": "^5.8|^6|^7|^8"
2020
},
2121
"require-dev": {
2222
"orchestra/testbench": "^3.6|^4.0|^5.0|^6.0",

docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM php:7.4-cli
1+
FROM php:8.0-cli
22

33
RUN apt-get update && apt-get install -y \
44
zlib1g-dev \
55
libzip-dev
66

77
RUN docker-php-ext-install zip
88

9-
RUN pecl install xdebug-2.8.1 \
9+
RUN pecl install xdebug-3.0.4 \
1010
&& docker-php-ext-enable xdebug
1111

1212
# Install composer and add its bin to the PATH.

readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ composer require korridor/laravel-computed-attributes
2323

2424
This package is tested for the following Laravel versions:
2525

26-
- 8.* (PHP 7.3, 7.4)
26+
- 8.* (PHP 7.3, 7.4, 8.0)
2727
- 7.* (PHP 7.2, 7.3, 7.4)
2828
- 6.* (PHP 7.2, 7.3)
29-
- 5.8.* (PHP 7.1, 7.2, 7.3)
30-
- 5.7.* (PHP 7.1, 7.2, 7.3, stable only)
3129

3230
## Usage examples
3331

src/ComputedAttributes.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait ComputedAttributes
1515
/**
1616
* Compute the given attribute and return the result.
1717
*
18-
* @param string $attributeName
18+
* @param string $attributeName
1919
* @return mixed
2020
*/
2121
public function getComputedAttributeValue(string $attributeName)
@@ -28,7 +28,7 @@ public function getComputedAttributeValue(string $attributeName)
2828
/**
2929
* Compute the given attribute and assign the result in the model.
3030
*
31-
* @param string $attributeName
31+
* @param string $attributeName
3232
*/
3333
public function setComputedAttributeValue(string $attributeName): void
3434
{
@@ -39,8 +39,8 @@ public function setComputedAttributeValue(string $attributeName): void
3939
/**
4040
* This scope will be applied during the computed property generation with artisan computed-attributes:generate.
4141
*
42-
* @param Builder $builder
43-
* @param array $attributes Attributes that will be generated.
42+
* @param Builder $builder
43+
* @param array $attributes Attributes that will be generated.
4444
* @return Builder
4545
*/
4646
public function scopeComputedAttributesGenerate(Builder $builder, array $attributes): Builder
@@ -51,8 +51,8 @@ public function scopeComputedAttributesGenerate(Builder $builder, array $attribu
5151
/**
5252
* This scope will be applied during the computed property validation with artisan computed-attributes:validate.
5353
*
54-
* @param Builder $builder
55-
* @param array $attributes Attributes that will be validated.
54+
* @param Builder $builder
55+
* @param array $attributes Attributes that will be validated.
5656
* @return Builder
5757
*/
5858
public function scopeComputedAttributesValidate(Builder $builder, array $attributes): Builder

src/Console/GenerateComputedAttributes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ class GenerateComputedAttributes extends Command
3737
* Execute the console command.
3838
*
3939
* @return int
40+
*
4041
* @throws ReflectionException
4142
*/
42-
public function handle()
43+
public function handle(): int
4344
{
4445
$modelsWithAttributes = $this->argument('modelsAttributes');
4546

@@ -61,6 +62,7 @@ public function handle()
6162
}
6263

6364
// Validate and parse modelsAttributes argument
65+
/** @var ModelAttributeParser $modelAttributeParser */
6466
$modelAttributeParser = app(ModelAttributeParser::class);
6567
try {
6668
$modelAttributesEntries = $modelAttributeParser->getModelAttributeEntries($modelsWithAttributes);

src/Console/ValidateComputedAttributes.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ class ValidateComputedAttributes extends Command
3737
* Execute the console command.
3838
*
3939
* @return int
40+
*
4041
* @throws ReflectionException
4142
*/
42-
public function handle()
43+
public function handle(): int
4344
{
4445
$modelsWithAttributes = $this->argument('modelsAttributes');
4546

@@ -61,6 +62,7 @@ public function handle()
6162
}
6263

6364
// Validate and parse modelsAttributes argument
65+
/** @var ModelAttributeParser $modelAttributeParser */
6466
$modelAttributeParser = app(ModelAttributeParser::class);
6567
try {
6668
$modelAttributesEntries = $modelAttributeParser->getModelAttributeEntries($modelsWithAttributes);
@@ -103,9 +105,9 @@ public function handle()
103105

104106
/**
105107
* @param $var
106-
* @return false|string
108+
* @return string
107109
*/
108-
private function varToString($var)
110+
private function varToString($var): string
109111
{
110112
if ($var === null) {
111113
return 'null';

src/LaravelComputedAttributesServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ class LaravelComputedAttributesServiceProvider extends ServiceProvider
1313
/**
1414
* Register services.
1515
*/
16-
public function register()
16+
public function register(): void
1717
{
1818
}
1919

2020
/**
2121
* Bootstrap services.
2222
*/
23-
public function boot()
23+
public function boot(): void
2424
{
2525
if ($this->app->runningInConsole()) {
2626
$this->publishes([

src/Parser/ModelAttributeParser.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public function getModelNamespaceBase(): string
3636

3737
/**
3838
* Get all models classes that use the ComputedAttributes trait.
39+
*
3940
* @return array
41+
*
4042
* @throws ReflectionException
4143
*/
42-
public function getAllModelClasses()
44+
public function getAllModelClasses(): array
4345
{
4446
// Get all models with trait
4547
$classmap = ClassMapGenerator::createMap($this->getAbsolutePathOfModelFolder());
@@ -58,12 +60,13 @@ public function getAllModelClasses()
5860
}
5961

6062
/**
61-
* @param string|null $modelsWithAttributes
63+
* @param string|null $modelsWithAttributes
6264
* @return ModelAttributesEntry[]
65+
*
6366
* @throws ParsingException
6467
* @throws ReflectionException
6568
*/
66-
public function getModelAttributeEntries(?string $modelsWithAttributes = null)
69+
public function getModelAttributeEntries(?string $modelsWithAttributes = null): array
6770
{
6871
$modelAttributesToProcess = [];
6972
$models = $this->getAllModelClasses();

src/Parser/ModelAttributesEntry.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ class ModelAttributesEntry
1616

1717
/**
1818
* ModelAttributesEntry constructor.
19-
* @param string $model
20-
* @param string[] $attributes
19+
*
20+
* @param string $model
21+
* @param string[] $attributes
2122
*/
2223
public function __construct(string $model, array $attributes)
2324
{

0 commit comments

Comments
 (0)