Skip to content

Commit

Permalink
Add phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Feb 4, 2022
1 parent c417efe commit d40293c
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 83 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: PHPStan

on:
push:
paths:
- '**.php'
- 'phpstan.neon.dist'

jobs:
phpstan:
name: phpstan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v1

- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
34 changes: 0 additions & 34 deletions .github/workflows/psalm.yml

This file was deleted.

8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
"mockery/mockery": "^1.4",
"orchestra/testbench": "^6.23|^7.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-laravel": "^1.5",
"spatie/phpunit-snapshot-assertions": "^4.2",
"vimeo/psalm": "^4.13"
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"nunomaduro/larastan": "^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -44,7 +46,7 @@
}
},
"scripts": {
"psalm": "vendor/bin/psalm --no-diff --no-cache",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
Expand Down
32 changes: 32 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
parameters:
ignoreErrors:
-
message: "#^Property 'group' does not exist in Spatie\\\\LaravelSettings\\\\Models\\\\SettingsProperty model\\.$#"
count: 1
path: src/Models/SettingsProperty.php

-
message: "#^Property 'name' does not exist in Spatie\\\\LaravelSettings\\\\Models\\\\SettingsProperty model\\.$#"
count: 1
path: src/Models/SettingsProperty.php

-
message: "#^Property Spatie\\\\LaravelSettings\\\\SettingsConfig\\:\\:\\$casts \\(Illuminate\\\\Support\\\\Collection\\<string, Spatie\\\\LaravelSettings\\\\SettingsCasts\\\\SettingsCast\\|null\\>\\) does not accept Illuminate\\\\Support\\\\Collection\\<int, Spatie\\\\LaravelSettings\\\\SettingsCasts\\\\SettingsCast\\|null\\>\\.$#"
count: 1
path: src/SettingsConfig.php

-
message: "#^Property Spatie\\\\LaravelSettings\\\\SettingsConfig\\:\\:\\$reflectionProperties \\(Illuminate\\\\Support\\\\Collection\\<string, ReflectionProperty\\>\\) does not accept Illuminate\\\\Support\\\\Collection\\<int, ReflectionProperty\\>\\.$#"
count: 1
path: src/SettingsConfig.php

-
message: "#^Access to an undefined property Illuminate\\\\Database\\\\Eloquent\\\\Model\\:\\:\\$name\\.$#"
count: 1
path: src/SettingsRepositories/DatabaseSettingsRepository.php

-
message: "#^Access to an undefined property Illuminate\\\\Database\\\\Eloquent\\\\Model\\:\\:\\$payload\\.$#"
count: 1
path: src/SettingsRepositories/DatabaseSettingsRepository.php

13 changes: 13 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
includes:
- phpstan-baseline.neon

parameters:
level: 4
paths:
- src
- config
- database
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false
36 changes: 0 additions & 36 deletions psalm.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function fake(array $values): self
));
}

public function __construct(array $values = [])
final public function __construct(array $values = [])
{
$this->ensureConfigIsLoaded();

Expand Down
6 changes: 1 addition & 5 deletions src/SettingsCasts/DateTimeInterfaceCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public function get($payload): ?DateTimeInterface
throw new Exception("Could not cast DateTime type `{$this->type}`");
}

/**
* @param DateTimeInterface $payload
*
* @return null|string
*/
/** @param DateTimeInterface|null $payload */
public function set($payload): ?string
{
return $payload !== null
Expand Down
6 changes: 3 additions & 3 deletions src/SettingsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

class SettingsConfig
{
/** @var string|\Spatie\LaravelSettings\Settings */
/** @var class-string<\Spatie\LaravelSettings\Settings> */
private string $settingsClass;

/** @var array<string, ?\Spatie\LaravelSettings\SettingsCasts\SettingsCast>|\Illuminate\Support\Collection */
/** @var Collection<string, ?\Spatie\LaravelSettings\SettingsCasts\SettingsCast> */
private Collection $casts;

/** @var array<string, \ReflectionProperty>|\Illuminate\Support\Collection */
/** @var Collection<string, \ReflectionProperty> */
private Collection $reflectionProperties;

/** @var string[]|\Illuminate\Support\Collection */
Expand Down
2 changes: 1 addition & 1 deletion src/SettingsRepositories/DatabaseSettingsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getPropertiesInGroup(string $group): array
return $this->getBuilder()
->where('group', $group)
->get(['name', 'payload'])
->mapWithKeys(function ($object) {
->mapWithKeys(function (object $object) {
return [$object->name => json_decode($object->payload, true)];
})
->toArray();
Expand Down

0 comments on commit d40293c

Please sign in to comment.