Skip to content

Phpstan max level + lots more type coverage #167

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 10 commits into from
Oct 21, 2020
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
4 changes: 2 additions & 2 deletions .github/workflows/php-workshop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
- name: Run phpcs
run: composer cs

# - name: Run phpstan
# run: composer static
- name: Run phpstan
run: composer static

- name: Coverage upload
if: matrix.php == '7.4'
Expand Down
5 changes: 0 additions & 5 deletions .scrutinizer.yml

This file was deleted.

8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
"require-dev": {
"composer/composer": "^1.2",
"squizlabs/php_codesniffer": "^3.4",
"symfony/phpunit-bridge": "^5.1"
"symfony/phpunit-bridge": "^5.1",
"phpstan/phpstan": "^0.12.50",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan-symfony": "^0.12.8"
},
"autoload" : {
"psr-4" : {
Expand All @@ -54,6 +57,7 @@
"cs" : [
"phpcs src --standard=PSR12 --encoding=UTF-8",
"phpcs test --standard=PSR12 --encoding=UTF-8"
]
],
"static": "phpstan --ansi analyse --level max src"
}
}
173 changes: 172 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
treatPhpDocTypesAsCertain: false
ignoreErrors:
-
message: '#PhpSchool\\PhpWorkshop\\ExerciseRunner\\CliRunner\:\:preserveOldArgFormat\(\) should return#'
path: src/ExerciseRunner/CliRunner.php
-
message: '#Call to an undefined method PhpParser\\Node\\Expr\|PhpParser\\Node\\Name\:\:__toString\(\)#'
path: src/Check/FunctionRequirementsCheck.php
32 changes: 16 additions & 16 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ final class Application
private $workshopTitle;

/**
* @var array
* @var array<class-string>
*/
private $checks = [];

/**
* @var ExerciseInterface[]
* @var array<class-string>
*/
private $exercises = [];

/**
* @var array
* @var array<array{resultClass: class-string, resultRendererClass: class-string}>
*/
private $results = [];

Expand Down Expand Up @@ -68,7 +68,7 @@ final class Application
* @param string $workshopTitle The workshop title - this is used throughout the application
* @param string $diConfigFile The absolute path to the DI configuration file
*/
public function __construct($workshopTitle, $diConfigFile)
public function __construct(string $workshopTitle, string $diConfigFile)
{
Assertion::string($workshopTitle);
Assertion::file($diConfigFile);
Expand All @@ -81,9 +81,9 @@ public function __construct($workshopTitle, $diConfigFile)
* Register a custom check with the application. Exercises will only be able to use the check
* if it has been registered here.
*
* @param string $check The FQCN of the check
* @param class-string $check The FQCN of the check
*/
public function addCheck($check)
public function addCheck(string $check): void
{
$this->checks[] = $check;
}
Expand All @@ -92,18 +92,18 @@ public function addCheck($check)
* Register an exercise with the application. Only exercises registered here will
* be displayed in the exercise menu.
*
* @param string $exercise The FQCN of the check
* @param class-string $exercise The FQCN of the check
*/
public function addExercise($exercise)
public function addExercise(string $exercise): void
{
$this->exercises[] = $exercise;
}

/**
* @param string $resultClass
* @param string $resultRendererClass
* @param class-string $resultClass
* @param class-string $resultRendererClass
*/
public function addResult($resultClass, $resultRendererClass)
public function addResult(string $resultClass, string $resultRendererClass): void
{
Assertion::classExists($resultClass);
Assertion::classExists($resultRendererClass);
Expand All @@ -120,7 +120,7 @@ public function addResult($resultClass, $resultRendererClass)
*
* @param string $logo The logo
*/
public function setLogo($logo)
public function setLogo(string $logo): void
{
Assertion::string($logo);
$this->logo = $logo;
Expand All @@ -132,7 +132,7 @@ public function setLogo($logo)
*
* @param string $colour The colour
*/
public function setFgColour($colour)
public function setFgColour(string $colour): void
{
Assertion::string($colour);
$this->fgColour = $colour;
Expand All @@ -144,7 +144,7 @@ public function setFgColour($colour)
*
* @param string $colour The colour
*/
public function setBgColour($colour)
public function setBgColour(string $colour): void
{
Assertion::string($colour);
$this->bgColour = $colour;
Expand All @@ -156,7 +156,7 @@ public function setBgColour($colour)
*
* @return int The exit code
*/
public function run()
public function run(): int
{
$container = $this->getContainer();

Expand Down Expand Up @@ -218,7 +218,7 @@ public function run()
/**
* @return \DI\Container
*/
private function getContainer()
private function getContainer(): \DI\Container
{
$containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions(
Expand Down
10 changes: 7 additions & 3 deletions src/Check/CheckRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
class CheckRepository
{
/**
* @var CheckInterface[]
* @var array<CheckInterface>
*/
private $checks = [];

/**
* @param CheckInterface[] $checks An array of checks available to the workshop framework.
* @param array<CheckInterface> $checks An array of checks available to the workshop framework.
*/
public function __construct(array $checks = [])
{
Expand All @@ -27,6 +27,7 @@ public function __construct(array $checks = [])

/**
* Add a new check to the repository.
* @param CheckInterface $check
*/
public function registerCheck(CheckInterface $check): void
{
Expand All @@ -36,7 +37,7 @@ public function registerCheck(CheckInterface $check): void
/**
* Get all of the checks in the repository.
*
* @return array
* @return array<CheckInterface>
*/
public function getAll(): array
{
Expand All @@ -61,6 +62,9 @@ public function getByClass(string $class): CheckInterface

/**
* Query whether a check instance exists in this repository via its class name.
*
* @param string $class
* @return bool
*/
public function has(string $class): bool
{
Expand Down
Loading