Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Php cs fixer on CI #211

Merged
merged 2 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
name: PHPCS check
name: PHP CS check

on:
push:
pull_request:
schedule:
- cron: '0 0 * * *'
on: [push]

jobs:
phpcs:
name: PHPCS
name: PHP CS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -21,7 +20,5 @@ jobs:
- name: Install dependencies
run: export COMPOSER_ROOT_VERSION=dev-master && composer install --prefer-dist --no-progress --no-suggest

- name: PHPCS check
uses: chekalsky/phpcs-action@v1
with:
phpcs_bin_path: './vendor/bin/phpcs'
- name: PHP CS check
run: 'composer lint'
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<config name="installed_paths" value="../../slevomat/coding-standard"/>
<rule ref="PSR2" />
<rule ref="PSR12" />
<!-- Forbid usage of a function or a class constant via fallback global name -->
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
Expand Down
3 changes: 2 additions & 1 deletion src/Fakes/FakeModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator;

use function config;
use function get_class;
use function implode;
Expand Down Expand Up @@ -37,7 +38,7 @@ public function getModels()
*
* @param Model $model
*/
protected function getPropertiesFromTable($model) : void
protected function getPropertiesFromTable($model): void
{
$table_name = $model->getTable();

Expand Down
3 changes: 2 additions & 1 deletion src/Handlers/Application/ContainerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Psalm\Type\Union;
use ReflectionClass;
use Throwable;

use function array_filter;
use function array_keys;
use function get_class;
Expand Down Expand Up @@ -54,7 +55,7 @@ public static function getClassLikeNames(): array
return [get_class(ApplicationProvider::getApp())];
}

public static function getMethodReturnType(MethodReturnTypeProviderEvent $event) : ?Type\Union
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Type\Union
{
// lumen doesn't have the likes of makeWith, so we will ensure these methods actually exist on the underlying
// app contract
Expand Down
1 change: 1 addition & 0 deletions src/Handlers/Application/OffsetHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Psalm\Plugin\EventHandler\MethodReturnTypeProviderInterface;
use Psalm\Plugin\EventHandler\MethodVisibilityProviderInterface;
use Psalm\Type;

use function in_array;

final class OffsetHandler implements
Expand Down
10 changes: 7 additions & 3 deletions src/Handlers/Eloquent/ModelMethodHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Psalm\LaravelPlugin\Handlers\Eloquent;

Expand All @@ -17,6 +19,7 @@
use Psalm\Plugin\EventHandler\MethodReturnTypeProviderInterface;
use Psalm\Type;
use Psalm\Type\Union;

use function strtolower;

final class ModelMethodHandler implements MethodReturnTypeProviderInterface, AfterClassLikeVisitInterface
Expand All @@ -29,7 +32,7 @@ public static function getClassLikeNames(): array
return [Model::class];
}

public static function getMethodReturnType(MethodReturnTypeProviderEvent $event) : ?Type\Union
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Type\Union
{
$source = $event->getSource();

Expand Down Expand Up @@ -73,7 +76,8 @@ public static function getMethodReturnType(MethodReturnTypeProviderEvent $event)
public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event)
{
$storage = $event->getStorage();
if ($event->getStmt() instanceof Class_
if (
$event->getStmt() instanceof Class_
&& !$storage->abstract
&& isset($storage->parent_classes[strtolower(Model::class)])
) {
Expand Down
1 change: 1 addition & 0 deletions src/Handlers/Eloquent/ModelPropertyAccessorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Psalm\Plugin\EventHandler\PropertyTypeProviderInterface;
use Psalm\Plugin\EventHandler\PropertyVisibilityProviderInterface;
use Psalm\Type;

use function str_replace;

final class ModelPropertyAccessorHandler implements PropertyExistenceProviderInterface, PropertyVisibilityProviderInterface, PropertyTypeProviderInterface
Expand Down
9 changes: 5 additions & 4 deletions src/Handlers/Eloquent/ModelRelationshipPropertyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Psalm\Type;
use Psalm\Type\Atomic\TGenericObject;
use Psalm\Type\Union;

use function in_array;

class ModelRelationshipPropertyHandler implements
Expand All @@ -28,12 +29,12 @@ class ModelRelationshipPropertyHandler implements
PropertyTypeProviderInterface
{
/** @return array<string, string> */
public static function getClassLikeNames() : array
public static function getClassLikeNames(): array
{
return ModelStubProvider::getModelClasses();
}

public static function doesPropertyExist(PropertyExistenceProviderEvent $event) : ?bool
public static function doesPropertyExist(PropertyExistenceProviderEvent $event): ?bool
{
$source = $event->getSource();

Expand All @@ -58,7 +59,7 @@ public static function doesPropertyExist(PropertyExistenceProviderEvent $event)
return null;
}

public static function isPropertyVisible(PropertyVisibilityProviderEvent $event) : ?bool
public static function isPropertyVisible(PropertyVisibilityProviderEvent $event): ?bool
{
if (!$event->isReadMode()) {
return null;
Expand Down Expand Up @@ -86,7 +87,7 @@ public static function isPropertyVisible(PropertyVisibilityProviderEvent $event)
*
* @return ?Union
*/
public static function getPropertyType(PropertyTypeProviderEvent $event) : ?Union
public static function getPropertyType(PropertyTypeProviderEvent $event): ?Union
{
$source = $event->getSource();

Expand Down
9 changes: 6 additions & 3 deletions src/Handlers/Eloquent/RelationsMethodHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Psalm\LaravelPlugin\Handlers\Eloquent;

Expand Down Expand Up @@ -41,7 +43,7 @@ public static function getClassLikeNames(): array
];
}

public static function getMethodReturnType(MethodReturnTypeProviderEvent $event) : ?Union
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Union
{
$source = $event->getSource();

Expand All @@ -57,7 +59,8 @@ public static function getMethodReturnType(MethodReturnTypeProviderEvent $event)

// If this method name is on the builder object, proxy it over there

if ($source->getCodebase()->methods->methodExists(new MethodIdentifier(Builder::class, $method_name_lowercase)) ||
if (
$source->getCodebase()->methods->methodExists(new MethodIdentifier(Builder::class, $method_name_lowercase)) ||
$source->getCodebase()->methods->methodExists(new MethodIdentifier(QueryBuilder::class, $method_name_lowercase))
) {
$template_type_parameters = $event->getTemplateTypeParameters();
Expand Down
51 changes: 32 additions & 19 deletions src/Handlers/Eloquent/Schema/SchemaAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use PhpParser;

use function count;
use function is_string;
use function strtolower;
Expand All @@ -17,7 +18,7 @@ class SchemaAggregator
/**
* @param array<int, PhpParser\Node\Stmt> $stmts
*/
public function addStatements(array $stmts) : void
public function addStatements(array $stmts): void
{
foreach ($stmts as $stmt) {
if ($stmt instanceof PhpParser\Node\Stmt\Class_) {
Expand All @@ -29,10 +30,11 @@ public function addStatements(array $stmts) : void
/**
* @param array<int, PhpParser\Node\Stmt> $stmts
*/
private function addClassStatements(array $stmts) : void
private function addClassStatements(array $stmts): void
{
foreach ($stmts as $stmt) {
if ($stmt instanceof PhpParser\Node\Stmt\ClassMethod
if (
$stmt instanceof PhpParser\Node\Stmt\ClassMethod
&& $stmt->name->name === 'up'
&& $stmt->stmts
) {
Expand All @@ -44,10 +46,11 @@ private function addClassStatements(array $stmts) : void
/**
* @param array<int, PhpParser\Node\Stmt> $stmts
*/
private function addUpMethodStatements(array $stmts) : void
private function addUpMethodStatements(array $stmts): void
{
foreach ($stmts as $stmt) {
if ($stmt instanceof PhpParser\Node\Stmt\Expression
if (
$stmt instanceof PhpParser\Node\Stmt\Expression
&& $stmt->expr instanceof PhpParser\Node\Expr\StaticCall
&& $stmt->expr->class instanceof PhpParser\Node\Name
&& $stmt->expr->name instanceof PhpParser\Node\Identifier
Expand All @@ -74,9 +77,10 @@ private function addUpMethodStatements(array $stmts) : void
}
}

private function alterTable(PhpParser\Node\Expr\StaticCall $call, bool $creating) : void
private function alterTable(PhpParser\Node\Expr\StaticCall $call, bool $creating): void
{
if (!isset($call->args[0])
if (
!isset($call->args[0])
|| !$call->args[0] instanceof PhpParser\Node\Arg
|| !$call->args[0]->value instanceof PhpParser\Node\Scalar\String_
) {
Expand All @@ -89,7 +93,8 @@ private function alterTable(PhpParser\Node\Expr\StaticCall $call, bool $creating
$this->tables[$table_name] = new SchemaTable($table_name);
}

if (!isset($call->args[1])
if (
!isset($call->args[1])
|| !$call->args[1] instanceof PhpParser\Node\Arg
|| !$call->args[1]->value instanceof PhpParser\Node\Expr\Closure
|| count($call->args[1]->value->params) < 1
Expand All @@ -102,7 +107,8 @@ private function alterTable(PhpParser\Node\Expr\StaticCall $call, bool $creating

$update_closure = $call->args[1]->value;

if ($call->args[1]->value->params[0]->var instanceof PhpParser\Node\Expr\Variable
if (
$call->args[1]->value->params[0]->var instanceof PhpParser\Node\Expr\Variable
&& is_string($call->args[1]->value->params[0]->var->name)
) {
$call_arg_name = $call->args[1]->value->params[0]->var->name;
Expand All @@ -111,9 +117,10 @@ private function alterTable(PhpParser\Node\Expr\StaticCall $call, bool $creating
}
}

private function dropTable(PhpParser\Node\Expr\StaticCall $call) : void
private function dropTable(PhpParser\Node\Expr\StaticCall $call): void
{
if (!isset($call->args[0])
if (
!isset($call->args[0])
|| !$call->args[0] instanceof PhpParser\Node\Arg
|| !$call->args[0]->value instanceof PhpParser\Node\Scalar\String_
) {
Expand All @@ -125,9 +132,10 @@ private function dropTable(PhpParser\Node\Expr\StaticCall $call) : void
unset($this->tables[$table_name]);
}

private function renameTable(PhpParser\Node\Expr\StaticCall $call) : void
private function renameTable(PhpParser\Node\Expr\StaticCall $call): void
{
if (!isset($call->args[0], $call->args[1])
if (
!isset($call->args[0], $call->args[1])
|| !$call->args[0] instanceof PhpParser\Node\Arg
|| !$call->args[0]->value instanceof PhpParser\Node\Scalar\String_
|| !$call->args[1] instanceof PhpParser\Node\Arg
Expand All @@ -152,7 +160,7 @@ private function renameTable(PhpParser\Node\Expr\StaticCall $call) : void
$this->tables[$new_table_name] = $table;
}

private function processColumnUpdates(string $table_name, string $call_arg_name, array $stmts) : void
private function processColumnUpdates(string $table_name, string $call_arg_name, array $stmts): void
{
if (!isset($this->tables[$table_name])) {
return;
Expand All @@ -161,7 +169,8 @@ private function processColumnUpdates(string $table_name, string $call_arg_name,
$table = $this->tables[$table_name];

foreach ($stmts as $stmt) {
if ($stmt instanceof PhpParser\Node\Stmt\Expression
if (
$stmt instanceof PhpParser\Node\Stmt\Expression
&& $stmt->expr instanceof PhpParser\Node\Expr\MethodCall
&& $stmt->expr->name instanceof PhpParser\Node\Identifier
) {
Expand All @@ -172,7 +181,8 @@ private function processColumnUpdates(string $table_name, string $call_arg_name,
$nullable = false;

while ($root_var instanceof PhpParser\Node\Expr\MethodCall) {
if ($root_var->name instanceof PhpParser\Node\Identifier
if (
$root_var->name instanceof PhpParser\Node\Identifier
&& $root_var->name->name === 'nullable'
) {
$nullable = true;
Expand All @@ -182,15 +192,17 @@ private function processColumnUpdates(string $table_name, string $call_arg_name,
$root_var = $root_var->var;
}

if ($root_var instanceof PhpParser\Node\Expr\Variable
if (
$root_var instanceof PhpParser\Node\Expr\Variable
&& $root_var->name === $call_arg_name
&& $first_method_call->name instanceof PhpParser\Node\Identifier
) {
$first_arg = $first_method_call->args[0]->value ?? null;
$second_arg = $first_method_call->args[1]->value ?? null;

if (!$first_arg instanceof PhpParser\Node\Scalar\String_) {
if ($first_method_call->name->name === 'timestamps'
if (
$first_method_call->name->name === 'timestamps'
|| $first_method_call->name->name === 'timestampsTz'
|| $first_method_call->name->name === 'nullableTimestamps'
|| $first_method_call->name->name === 'nullableTimestampsTz'
Expand Down Expand Up @@ -228,7 +240,8 @@ private function processColumnUpdates(string $table_name, string $call_arg_name,
}

continue;
} elseif ($first_method_call->name->name === 'softDeletes'
} elseif (
$first_method_call->name->name === 'softDeletes'
|| $first_method_call->name->name === 'softDeletesTz'
|| $first_method_call->name->name === 'dropSoftDeletes'
|| $first_method_call->name->name === 'dropSoftDeletesTz'
Expand Down
6 changes: 3 additions & 3 deletions src/Handlers/Eloquent/Schema/SchemaTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public function __construct(string $name)
$this->name = $name;
}

public function setColumn(SchemaColumn $column) : void
public function setColumn(SchemaColumn $column): void
{
$this->columns[$column->name] = $column;
}

public function renameColumn(string $old_name, string $new_name) : void
public function renameColumn(string $old_name, string $new_name): void
{
if (!isset($this->columns[$old_name])) {
return;
Expand All @@ -35,7 +35,7 @@ public function renameColumn(string $old_name, string $new_name) : void
$this->columns[$new_name] = $old_column;
}

public function dropColumn(string $column_name) : void
public function dropColumn(string $column_name): void
{
unset($this->columns[$column_name]);
}
Expand Down
Loading