Skip to content

feat: 🎸 Improve code quality and support PHPStan #14

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

Merged
merged 1 commit into from
Nov 19, 2021
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
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

strategy:
matrix:
php: [7.3, 7.4, '8.0', 8.1]
php: [7.4, '8.0', 8.1]
lib:
- { laravel: ^9.0 }
- { laravel: ^8.0 }
Expand All @@ -36,7 +36,11 @@ jobs:
- { php: 8.1, lib: { laravel: ^6.0 } }
- { php: 8.1, lib: { laravel: ^6.0, flags: --prefer-lowest } }
- { php: 7.4, lib: { laravel: ^9.0 } }
- { php: 7.3, lib: { laravel: ^9.0 } }
include:
- { php: 8.1, lib: { laravel: ^9.0 }, phpstan: '1' }
- { php: 8.1, lib: { laravel: ^8.0 }, phpstan: '1' }
- { php: '8.0', lib: { laravel: ^9.0 }, phpstan: '1' }
- { php: '8.0', lib: { laravel: ^8.0 }, phpstan: '1' }

steps:
- uses: actions/checkout@v2
Expand All @@ -51,6 +55,10 @@ jobs:
run: |
composer require "laravel/framework:${{ matrix.lib.laravel }}" --dev ${{ matrix.lib.flags }}

- name: PHPStan
if: ${{ matrix.phpstan }}
run: composer phpstan

- run: mkdir -p build/logs
- run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
composer.lock
/.idea/
/vendor/
/build/logs/
.php_cs.cache
Expand Down
11 changes: 5 additions & 6 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ checks:

filter:
excluded_paths:
- phpstan/*
- tests/*
- vendor/*

Expand All @@ -14,12 +15,6 @@ build:
tests:
override:
- php-scrutinizer-run

environment:
php: '7.4'
docker: true

nodes:
custom-nodes:
services:
custom-mysql:
Expand All @@ -32,6 +27,10 @@ build:
ports:
- 3306

environment:
php: '7.4'
docker: true

dependencies:
before:
- composer install
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ A tiny extension of `MySqlConnection` that manages **session** system variables

## Requirements

- PHP: `^7.3 || ^8.0`
- Laravel: `^6.0 || ^7.0 || ^8.0 || ^9.0`
| Package | Version | Mandatory |
|:---|:---|:---:|
| PHP | <code>^7.4 &#124;&#124; ^8.0</code> | ✅ |
| Laravel | <code>^6.0 &#124;&#124; ^7.0 &#124;&#124; ^8.0 &#124;&#124; ^9.0</code> | ✅ |
| PHPStan | <code>&gt;=1.1</code> | |

## Installing

Expand Down
165 changes: 165 additions & 0 deletions _ide_helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php

namespace Illuminate\Database
{
if (false) {
interface ConnectionInterface
{
/**
* Set MySQL system variable for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param mixed $value
* @return $this
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public function setSystemVariable(string $key, $value, bool $memoizeForReconnect = true);

/**
* Set MySQL system variables for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param array $values
* @param bool $memoizeForReconnect
* @return $this
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public function setSystemVariables(array $values, bool $memoizeForReconnect = true);

/**
* Run callback temporarily setting MySQL system variable for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param mixed $value
* @param mixed ...$args
* @return mixed
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public function usingSystemVariable(string $key, $value, callable $callback, ...$args);

/**
* Run callback temporarily setting MySQL system variables for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param array $values
* @param mixed ...$args
* @return mixed
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public function usingSystemVariables(array $values, callable $callback, ...$args);
}

class Connection implements ConnectionInterface
{
/**
* Set MySQL system variable for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param mixed $value
* @return $this
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public function setSystemVariable(string $key, $value, bool $memoizeForReconnect = true)
{
}

/**
* Set MySQL system variables for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param array $values
* @param bool $memoizeForReconnect
* @return $this
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public function setSystemVariables(array $values, bool $memoizeForReconnect = true)
{
}

/**
* Run callback temporarily setting MySQL system variable for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param mixed $value
* @param mixed ...$args
* @return mixed
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public function usingSystemVariable(string $key, $value, callable $callback, ...$args)
{
}

/**
* Run callback temporarily setting MySQL system variables for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param array $values
* @param mixed ...$args
* @return mixed
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public function usingSystemVariables(array $values, callable $callback, ...$args)
{
}
}
}
}

namespace Illuminate\Support\Facades
{
if (false) {
class DB extends Facade
{
/**
* Set MySQL system variable for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param mixed $value
* @return \Illuminate\Database\Connection
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public static function setSystemVariable(string $key, $value, bool $memoizeForReconnect = true)
{
}

/**
* Set MySQL system variables for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param array $values
* @param bool $memoizeForReconnect
* @return \Illuminate\Database\Connection
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public static function setSystemVariables(array $values, bool $memoizeForReconnect = true)
{
}

/**
* Run callback temporarily setting MySQL system variable for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param mixed $value
* @param mixed ...$args
* @return mixed
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public static function usingSystemVariable(string $key, $value, callable $callback, ...$args)
{
}

/**
* Run callback temporarily setting MySQL system variables for both read and write PDOs.
* It is lazily executed for unresolved PDO instance.
*
* @param array $values
* @param mixed ...$args
* @return mixed
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
*/
public static function usingSystemVariables(array $values, callable $callback, ...$args)
{
}
}
}
}
27 changes: 21 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"keywords": ["laravel", "illuminate", "mysql", "system", "variable"],
"autoload": {
"psr-4": {
"Mpyw\\LaravelMySqlSystemVariableManager\\": "src/"
"Mpyw\\LaravelMySqlSystemVariableManager\\": "src/",
"Mpyw\\LaravelMySqlSystemVariableManager\\PHPStan\\": "phpstan/"
}
},
"autoload-dev": {
Expand All @@ -21,18 +22,32 @@
}
},
"require": {
"php": "^7.3 || ^8.0",
"php": "^7.4 || ^8.0",
"ext-pdo": "*",
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"mpyw/unclosure": "^1.0",
"mpyw/laravel-pdo-emulation-control": "^1.0"
"mpyw/unclosure": "^3.0",
"mpyw/laravel-pdo-emulation-control": "^2.0.2"
},
"require-dev": {
"orchestra/testbench": "*",
"orchestra/testbench-core": "^4.9 || ^5.9 || >=6.6",
"phpunit/phpunit": ">=9.5"
"phpunit/phpunit": ">=9.5",
"phpstan/phpstan": ">=1.1",
"phpstan/extension-installer": ">=1.1",
"nunomaduro/larastan": "^1.0"
},
"scripts": {
"test": "vendor/bin/phpunit",
"phpstan": "vendor/bin/phpstan analyse src tests phpstan"
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"extra": {
"phpstan": {
"includes": [
"extension.neon"
]
}
}
}
13 changes: 13 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
-
class: Mpyw\LaravelMySqlSystemVariableManager\PHPStan\ConnectionClassExtension
tags:
- phpstan.broker.methodsClassReflectionExtension
-
class: Mpyw\LaravelMySqlSystemVariableManager\PHPStan\CallableReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
class: Mpyw\LaravelMySqlSystemVariableManager\PHPStan\CallableFacadeReturnTypeExtension
tags:
- phpstan.broker.dynamicStaticMethodReturnTypeExtension
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- ./extension.neon

parameters:
level: 9
checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- message: '#Cannot access property \$value on mixed#'
path: tests
41 changes: 41 additions & 0 deletions phpstan/CallableArgumentParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Mpyw\LaravelMySqlSystemVariableManager\PHPStan;

use PHPStan\Reflection\ParameterReflection;
use PHPStan\Reflection\PassedByReference;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;

final class CallableArgumentParameter implements ParameterReflection
{
public function getName(): string
{
return 'args';
}

public function isOptional(): bool
{
return false;
}

public function getType(): Type
{
return new MixedType();
}

public function passedByReference(): PassedByReference
{
return PassedByReference::createNo();
}

public function isVariadic(): bool
{
return false;
}

public function getDefaultValue(): ?Type
{
return null;
}
}
Loading