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

Post release hotfixes #18

Merged
merged 3 commits into from
Apr 27, 2019
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/build/
/cache/
/composer.lock
/docs/api/
/.env
/.phpcheck/
/.php_cs.cache
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ watch:
watch-playground:
while inotifywait -e close_write -r composer.* ./src ./checks ./functions ./playground ./tests; do php playground/test.php; done

docs-build:
php sami.phar update sami.config.php

docs-clean:
rm -rf build/ cache/

phpcheck:
@phpcheck

Expand Down
2 changes: 1 addition & 1 deletion checks/GeneratorCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function checkFakerWithArgs(int $int): bool
}

/**
* @param int $int {@gen variant(123, choose(0, 1000000))}
* @param int $int {@gen variant("123", choose(0, 1000000))}
*/
public function checkVariant(int $int): bool
{
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.14",
"phpmd/phpmd": "^2.6",
"phpstan/phpstan": "^0.11.5",
"phpunit/phpunit": "^8.1"
},
"config": {
Expand Down
24 changes: 24 additions & 0 deletions sami.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Sami\RemoteRepository\GitHubRemoteRepository;
use Sami\Sami;
use Symfony\Component\Finder\Finder;

$iterator = Finder::create()
->files()
->name('*.php')
->in($dir = __DIR__.'/src');

return new Sami(
$iterator,
[
'default_opened_level' => 2,
'remote_repository' => new GitHubRemoteRepository('datashaman/phpcheck', dirname($dir)),
'sort_class_constants' => true,
'sort_class_interfaces' => true,
'sort_class_methods' => true,
'sort_class_properties' => true,
'sort_class_traits' => true,
'title' => 'PHPCheck API',
]
);
Binary file added sami.phar
Binary file not shown.
3 changes: 3 additions & 0 deletions src/Coverage/Coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
namespace Datashaman\PHPCheck\Coverage;

/**
* Abstract base class for coverage classes.
*/
abstract class Coverage
{
public function __destruct()
Expand Down
16 changes: 15 additions & 1 deletion src/Coverage/HtmlCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,29 @@

use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlFacade;

/**
* This class produces an HTML coverage report to a specified folder.
*/
class HtmlCoverage extends Coverage
{
private $folder;

public function __construct(string $folder)
{
$this->folder = $folder;
}

/**
* Processing is done in the __destruct method to ensure maximum coverage
* results.
*/
public function __destruct()
{
global $coverage;

parent::__destruct();

$writer = new HtmlFacade();
$writer->process($coverage, $this->input->getOption('coverage-html'));
$writer->process($coverage, $this->folder);
}
}
31 changes: 28 additions & 3 deletions src/Coverage/TextCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,35 @@
*/
namespace Datashaman\PHPCheck\Coverage;

use function Datashaman\PHPCheck\{
app,
};
use SebastianBergmann\CodeCoverage\Report\Text;

/**
* This class produces a text coverage report to standard output or a specified file.
*/
class TextCoverage extends Coverage
{
private $_output;
private $_noAnsi;

/**
* @param null|string $output
* @param null|bool $noAnsi
*/
public function __construct(
string $output = null,
bool $noAnsi = null
) {
$this->_output = $output;
$this->_noAnsi = $noAnsi;
}

/**
* Processing is done in the __destruct method to ensure maximum coverage
* results.
*/
public function __destruct()
{
global $coverage;
Expand All @@ -21,16 +46,16 @@ public function __destruct()

$writer = new Text();

if ($this->input->getOption('coverage-text')) {
if ($this->_output) {
$output = $writer->process($coverage, false);
\file_put_contents($this->input->getOption('coverage-text'), $output);
\file_put_contents($this->_output, $output);

return;
}

$color = true;

if ($this->input->getOption('no-ansi') !== false) {
if ($this->_noAnsi !== false) {
$color = false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/CheckError.php → src/Exceptions/CheckError.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Datashaman\PHPCheck;
namespace Datashaman\PHPCheck\Exceptions;

use Exception;

Expand Down
2 changes: 1 addition & 1 deletion src/Example.php → src/Exceptions/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Datashaman\PHPCheck;
namespace Datashaman\PHPCheck\Exceptions;

use Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Datashaman\PHPCheck;
namespace Datashaman\PHPCheck\Exceptions;

use Exception;
use Throwable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Datashaman\PHPCheck;
namespace Datashaman\PHPCheck\Exceptions;

use Exception;

Expand Down
61 changes: 28 additions & 33 deletions src/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public function getClass($class)
return new ReflectionClass($class);
}

public function getMethod($class, $method)
{
return new ReflectionMethod($class, $method);
}

public function getFunctionSignature(ReflectionFunction $function): string
{
return $function->getName();
Expand All @@ -39,34 +34,6 @@ public function getMethodSignature(ReflectionMethod $method): string
return $method->getDeclaringClass()->getName() . '::' . $method->getName();
}

public function getParamAnnotations($reflectionCallable): array
{
$factory = DocBlockFactory::createInstance();
$docComment = $reflectionCallable->getDocComment();

if ($docComment === false) {
return [];
}

$docBlock = $factory->create($docComment);

return $docBlock->getTagsByName('param');
}

public function getParamAnnotation(ReflectionParameter $param): ?Param
{
$method = $param->getDeclaringFunction();
$annotations = $this->getParamAnnotations($method);

foreach ($annotations as $annotation) {
if ($annotation->getVariableName() === $param->getName()) {
return $annotation;
}
}

return null;
}

public function getParamTags(ReflectionParameter $param): array
{
$annotation = $this->getParamAnnotation($param);
Expand Down Expand Up @@ -95,4 +62,32 @@ public function reflect($subject)

return $subject;
}

private function getParamAnnotations($reflectionCallable): array
{
$factory = DocBlockFactory::createInstance();
$docComment = $reflectionCallable->getDocComment();

if ($docComment === false) {
return [];
}

$docBlock = $factory->create($docComment);

return $docBlock->getTagsByName('param');
}

private function getParamAnnotation(ReflectionParameter $param): ?Param
{
$method = $param->getDeclaringFunction();
$annotations = $this->getParamAnnotations($method);

foreach ($annotations as $annotation) {
if ($annotation->getVariableName() === $param->getName()) {
return $annotation;
}
}

return null;
}
}
2 changes: 2 additions & 0 deletions src/Results/Failure.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
namespace Datashaman\PHPCheck\Results;

use Exception;

class Failure
{
/**
Expand Down
24 changes: 12 additions & 12 deletions src/RunState.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TEXT NOT NULL,
)
EOT;

protected const INSERT_RESULT_SQL = <<<'EOT'
private const INSERT_RESULT_SQL = <<<'EOT'
INSERT OR REPLACE INTO results (
class,
method,
Expand All @@ -44,17 +44,17 @@ class,
)
EOT;

protected const SELECT_DEFECT_SQL = <<<'EOT'
private const SELECT_DEFECT_SQL = <<<'EOT'
SELECT args FROM results WHERE class = :class AND method = :method AND status IN ('ERROR', 'FAILURE')
EOT;

protected $errors = [];
private $errors = [];

protected $failures = [];
private $failures = [];

protected $startTime;
private $startTime;

protected $successes = [];
private $successes = [];

public static function getSubscribedEvents(): array
{
Expand Down Expand Up @@ -90,22 +90,22 @@ public function getDefectArgs(ReflectionMethod $method): ?array
return null;
}

public function getErrors()
public function getErrors(): array
{
return $this->errors;
}

public function getFailures()
public function getFailures(): array
{
return $this->failures;
}

public function getSuccesses()
public function getSuccesses(): array
{
return $this->successes;
}

public function getStartTime()
public function getStartTime(): float
{
return $this->startTime;
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public function onSuccess(Events\SuccessEvent $event): void
$this->saveResult($event);
}

protected function saveResult(Events\ResultEvent $event): void
private function saveResult(Events\ResultEvent $event): void
{
$args = $event->args ? (\json_encode($event->args) ?: '') : '';

Expand All @@ -151,7 +151,7 @@ protected function saveResult(Events\ResultEvent $event): void
$statement->execute();
}

protected function formatMicrotime(float $microtime): string
private function formatMicrotime(float $microtime): string
{
$decimal = \preg_match('/^[0-9]*\\.([0-9]+)$/', (string) $microtime, $reg)
? \mb_substr(\str_pad($reg[1], 6, '0'), 0, 6)
Expand Down
Loading