Skip to content

Commit

Permalink
Allow Laravel 11
Browse files Browse the repository at this point in the history
Also use Larastan instead of PHPStan
  • Loading branch information
kblais committed Apr 16, 2024
1 parent 52ab032 commit eab1892
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 197 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.2, 8.1, 8.0]
laravel: [^10.0, ^9.0, ^8.0]
php: [8.3, 8.2, 8.1, 8.0]
laravel: [^11.0, ^10.0, ^9.0, ^8.0]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- laravel: ^10.0
php: 8.0
- laravel: ^11.0
php: 8.0
- laravel: ^11.0
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

Expand Down
157 changes: 0 additions & 157 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,163 +12,6 @@
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'array_syntax' => true,
'binary_operator_spaces' => true,
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => true,
'braces' => true,
'cast_spaces' => true,
'class_attributes_separation' => true,
'class_definition' => true,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'comment_to_phpdoc' => true,
'compact_nullable_typehint' => true,
'concat_space' => true,
'declare_equal_normalize' => true,
'dir_constant' => true,
'elseif' => true,
'encoding' => true,
'ereg_to_preg' => true,
'error_suppression' => true,
'escape_implicit_backslashes' => true,
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'final_internal_class' => true,
'fopen_flag_order' => true,
'fopen_flags' => true,
'full_opening_tag' => true,
'fully_qualified_strict_types' => true,
'function_declaration' => true,
'function_to_constant' => true,
'function_typehint_space' => true,
'heredoc_to_nowdoc' => true,
'implode_call' => true,
'include' => true,
'increment_style' => true,
'indentation_type' => true,
'is_null' => true,
'line_ending' => true,
'logical_operators' => true,
'lowercase_cast' => true,
'lowercase_keywords' => true,
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'magic_method_casing' => true,
'method_argument_space' => true,
'method_chaining_indentation' => true,
'modernize_types_casting' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => true,
'native_constant_invocation' => true,
'native_function_casing' => true,
'native_function_invocation' => true,
'new_with_braces' => true,
'no_alias_functions' => true,
'no_alternative_syntax' => true,
'no_binary_string' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_break_comment' => true,
'no_closing_tag' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_homoglyph_names' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'no_null_property_initialization' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_after_function_name' => true,
'no_spaces_around_offset' => true,
'no_spaces_inside_parenthesis' => true,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_unset_cast' => true,
'no_unset_on_property' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'non_printable_character' => true,
'normalize_index_brace' => true,
'object_operator_without_whitespace' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'php_unit_fqcn_annotation' => true,
'php_unit_internal_class' => true,
'php_unit_method_casing' => true,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_strict' => true,
'php_unit_test_annotation' => true,
'php_unit_test_case_static_method_calls' => false,
'php_unit_test_class_requires_covers' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_align' => true,
'phpdoc_annotation_without_dot' => true,
'phpdoc_indent' => true,
'phpdoc_no_access' => true,
'phpdoc_no_alias_tag' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_summary' => true,
'phpdoc_to_comment' => true,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => true,
'phpdoc_var_annotation_correct_order' => true,
'phpdoc_var_without_name' => true,
'protected_to_private' => true,
'return_assignment' => true,
'return_type_declaration' => true,
'self_accessor' => true,
'semicolon_after_instruction' => true,
'set_type_to_cast' => true,
'short_scalar_cast' => true,
'single_blank_line_at_eof' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'single_line_comment_style' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_increment' => true,
'standardize_not_equals' => true,
'strict_comparison' => true,
'strict_param' => true,
'string_line_ending' => true,
'switch_case_semicolon_to_colon' => true,
'switch_case_space' => true,
'ternary_operator_spaces' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'visibility_required' => true,
'whitespace_after_comma_in_array' => true,
'yoda_style' => true,
])
->setFinder(PhpCsFixer\Finder::create()
->exclude('vendor')
Expand Down
26 changes: 16 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"description": "A collection of helpers for your Laravel application.",
"require": {
"php": "^8.0",
"illuminate/database": "^8.13|^9.0|^10.0"
"illuminate/database": "^8.13|^9.0|^10.0|^11.0"
},
"require-dev": {
"orchestra/testbench": "^6.23|^7.0|^8.0",
"orchestra/testbench": "^6.23|^7.0|^8.0|^9.0",
"friendsofphp/php-cs-fixer": "^3.5",
"phpstan/phpstan": "^1.0"
"larastan/larastan": "^2.9"
},
"autoload": {
"psr-4": {
Expand All @@ -21,13 +21,19 @@
}
},
"scripts": {
"phpcs": "php-cs-fixer fix",
"phpunit": "phpunit --verbose --color=always",
"phpstan": "phpstan analyze --no-progress",
"test": [
"@phpstan",
"@phpunit",
"@phpcs"
"tests:cs": [
"@php ./vendor/bin/php-cs-fixer fix"
],
"tests:stan": [
"@php ./vendor/bin/phpstan analyze"
],
"tests:unit": [
"@php ./vendor/bin/phpunit --colors"
],
"tests": [
"@tests:cs",
"@tests:stan",
"@tests:unit"
]
},
"license": "MIT",
Expand Down
18 changes: 13 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
includes:
- ./vendor/larastan/larastan/extension.neon
parameters:
paths:
- './src'
- './tests'
level: 5
ignoreErrors:
paths:
- src
- tests

# The level 8 is the highest level
level: 5

checkMissingIterableValueType: false

ignoreErrors:
- '#Call to function property_exists\(\) with \$this#'
6 changes: 3 additions & 3 deletions src/Eloquent/OrderByDefaultOrderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public static function bootOrderByDefaultOrderTrait()
*/
public static function withoutDefaultOrder(): Builder
{
return with(new self())->newQueryWithoutScope(static::getOrderScope());
return (new self())->newQueryWithoutScope(static::getOrderScope());
}

public function getDefaultOrder(): array
{
if (property_exists($this, 'defaultOrder')) {
if (property_exists($this, 'defaultOrder') && !empty($this->defaultOrder)) {
return $this->defaultOrder;
}

Expand All @@ -46,7 +46,7 @@ public function getDefaultOrder(): array
*/
protected static function getOrderScope(): Scope
{
$defaultOrder = with(new self())->getDefaultOrder();
$defaultOrder = (new self())->getDefaultOrder();

return new OrderByScope(
Arr::get($defaultOrder, 'column'),
Expand Down
37 changes: 22 additions & 15 deletions tests/OrderByDefaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,61 @@
use Kblais\LaravelHelpers\Eloquent\OrderByDefaultOrderInterface;
use Kblais\LaravelHelpers\Eloquent\OrderByDefaultOrderTrait;

/**
* @internal
*
* @covers \Kblais\LaravelHelpers\Eloquent\OrderByDefaultOrderTrait
*/
final class OrderByDefaultTest extends TestCase
{
public function testModelHasDefaultDefaultOrder()
{
$user = new class() extends Model implements OrderByDefaultOrderInterface {
$user = new class () extends Model implements OrderByDefaultOrderInterface {
use OrderByDefaultOrderTrait;

protected $table = 'user';
};

$query = $user::query();
$query = $user::query()
->applyScopes()
->getQuery()
;

static::assertSame('select * from `user` order by `created_at` asc', $query->toSql());
$this->assertContains([
'column' => 'created_at',
'direction' => 'asc',
], $query->orders);
}

public function testRemoveDefaultOrder()
{
$user = new class() extends Model implements OrderByDefaultOrderInterface {
$user = new class () extends Model implements OrderByDefaultOrderInterface {
use OrderByDefaultOrderTrait;

protected $table = 'user';
};

$query = $user::withoutDefaultOrder();
$query = $user::withoutDefaultOrder()
->applyScopes()
->getQuery()
;

static::assertSame('select * from `user`', $query->toSql());
$this->assertEmpty($query->orders);
}

public function testModelHasCustomDefaultOrder()
{
$user = new class() extends Model implements OrderByDefaultOrderInterface {
$user = new class () extends Model implements OrderByDefaultOrderInterface {
use OrderByDefaultOrderTrait;

protected $table = 'user';

protected $defaultOrder = [
protected array $defaultOrder = [
'column' => 'id',
'asc' => false,
];
};

$query = $user::query();
$query = $user::query()->applyScopes()->getQuery();

static::assertSame('select * from `user` order by `id` desc', $query->toSql());
$this->assertContains([
'column' => 'id',
'direction' => 'desc',
], $query->orders);
}
}
5 changes: 0 additions & 5 deletions tests/SingularTableNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
use Illuminate\Database\Eloquent\Model;
use Kblais\LaravelHelpers\Eloquent\SingularTableNameTrait;

/**
* @internal
*
* @covers \Kblais\LaravelHelpers\Eloquent\SingularTableNameTrait
*/
final class SingularTableNameTest extends TestCase
{
public function testUserModelHasSingularTableName()
Expand Down

0 comments on commit eab1892

Please sign in to comment.