Skip to content
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: 12 additions & 0 deletions configDefaults/generic/codingStandard/ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<ruleset name="PHPQA">
<description>The PHPQA coding standard.</description>
<arg name="tab-width" value="4"/>

<!-- All of PSR12 //-->
<!-- see vendor/squizlabs/php_codesniffer/src/Standards/PSR12/ruleset.xml //-->
<rule ref="PSR12"/>



</ruleset>
4 changes: 2 additions & 2 deletions includes/generic/setConfig.inc.bash
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ phpstanConfigPath="$(configPath phpstan.neon)"
phpmdConfigPath="$(configPath phpmd/ruleset.xml)"

# coding Standard for checking
# checks for a folder called 'condingStandards' in the $projectConfigPath, falls back to the PSR2 standards
phpcsCodingStandardsNameOrPath="PSR2"
# For PSR2, you need to override this and set the value to "PSR2"
phpcsCodingStandardsNameOrPath="$(configPath codingStandard)"

# should coding standards warnings be a fail?
phpcsFailOnWarning=0
Expand Down
4 changes: 2 additions & 2 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public static function getProjectRootDirectory(): string
*/
public static function getComposerJsonDecoded(string $path = null): array
{
$path = $path ?? self::getProjectRootDirectory().'/composer.json';
$path = $path ?? self::getProjectRootDirectory() . '/composer.json';
$contents = (string)\file_get_contents($path);
if ('' === $contents) {
throw new \RuntimeException('composer.json is empty');
}
$decoded = \json_decode($contents, true);
if (JSON_ERROR_NONE !== \json_last_error()) {
throw new \RuntimeException('Failed loading composer.json: '.\json_last_error_msg());
throw new \RuntimeException('Failed loading composer.json: ' . \json_last_error_msg());
}

return $decoded;
Expand Down
16 changes: 8 additions & 8 deletions src/Markdown/LinksChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ private static function getFiles(string $projectRootDirectory): array
*/
private static function getMainReadme(string $projectRootDirectory): string
{
$path = $projectRootDirectory.'/README.md';
$path = $projectRootDirectory . '/README.md';
if (!is_file($path)) {
throw new \RuntimeException(
"\n\nYou have no README.md file in your project"
."\n\nAs the bear minimum you need to have this file to pass QA"
. "\n\nAs the bear minimum you need to have this file to pass QA"
);
}

Expand All @@ -48,7 +48,7 @@ private static function getMainReadme(string $projectRootDirectory): string
private static function getDocsFiles(string $projectRootDirectory): array
{
$files = [];
$dir = $projectRootDirectory.'/docs';
$dir = $projectRootDirectory . '/docs';
if (!is_dir($dir)) {
return $files;
}
Expand Down Expand Up @@ -120,13 +120,13 @@ private static function checkLink(
$start = \rtrim($projectRootDirectory, '/');
if ($path[0] !== '/' || 0 === \strpos($path, './')) {
$relativeSubdirs = \preg_replace(
'%^'.$projectRootDirectory.'%',
'%^' . $projectRootDirectory . '%',
'',
\dirname($file)
);
$start .= '/'.\rtrim($relativeSubdirs, '/');
$start .= '/' . \rtrim($relativeSubdirs, '/');
}
$realpath = \realpath($start.'/'.$path);
$realpath = \realpath($start . '/' . $path);
if (false === $realpath) {
$errors[] = \sprintf("\nBad link for \"%s\" to \"%s\"\n", $link[1], $link[2]);
$return = 1;
Expand All @@ -148,14 +148,14 @@ public static function main(string $projectRootDirectory = null): int
$files = static::getFiles($projectRootDirectory);
foreach ($files as $file) {
$relativeFile = str_replace($projectRootDirectory, '', $file);
$title = "\n$relativeFile\n".str_repeat('-', strlen($relativeFile))."\n";
$title = "\n$relativeFile\n" . str_repeat('-', strlen($relativeFile)) . "\n";
$errors = [];
$links = static::getLinks($file);
foreach ($links as $link) {
static::checkLink($projectRootDirectory, $link, $file, $errors, $return);
}
if ([] !== $errors) {
echo $title.implode('', $errors);
echo $title . implode('', $errors);
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/PHPUnit/CheckAnnotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function main(string $pathToTestsDirectory): array
{
if (!is_dir($pathToTestsDirectory)) {
throw new \InvalidArgumentException(
'$pathToTestsDirectory "'.$pathToTestsDirectory.'" does not exist"'
'$pathToTestsDirectory "' . $pathToTestsDirectory . '" does not exist"'
);
}
$this->largePath = $pathToTestsDirectory.'/Large';
$this->mediumPath = $pathToTestsDirectory.'/Medium';
$this->smallPath = $pathToTestsDirectory.'/Small';
$this->largePath = $pathToTestsDirectory . '/Large';
$this->mediumPath = $pathToTestsDirectory . '/Medium';
$this->smallPath = $pathToTestsDirectory . '/Small';
$this->checkLarge();
$this->checkMedium();
$this->checkSmall();
Expand Down Expand Up @@ -98,7 +98,7 @@ private function checkDirectory(string $path, string $annotation): void
private function checkFile(\SplFileInfo $fileInfo, string $annotation): void
{
$contents = (string)file_get_contents($fileInfo->getPathname());
if($this->isAnnotationInClassDocBlock($contents, $annotation) === true) {
if ($this->isAnnotationInClassDocBlock($contents, $annotation) === true) {
return;
}

Expand All @@ -107,7 +107,7 @@ private function checkFile(\SplFileInfo $fileInfo, string $annotation): void
<<<REGEXP
%(?<docblock>/\*(?:[^*]|\n|(?:\*(?:[^/]|\n)))*\*/|\n)\s+?public\s+?function\s+?(?<method>.+?)\(%
REGEXP
.'si',
. 'si',
$contents,
$matches
);
Expand All @@ -119,15 +119,15 @@ private function checkFile(\SplFileInfo $fileInfo, string $annotation): void
foreach ($matches['method'] as $key => $method) {
$docblock = $matches['docblock'][$key];
/* Found the annotation - continue */
if (false !== \strpos($docblock, '@'.$annotation)) {
if (false !== \strpos($docblock, '@' . $annotation)) {
continue;
}
/* No @test annotation found & method not beginning test = not a test, so continue */
if (false === \strpos($docblock, '@test') && false === \strpos($method, 'test')) {
continue;
}
$this->errors[$fileInfo->getFilename()][] =
'Failed finding @'.$annotation.' for method: '.$method;
'Failed finding @' . $annotation . ' for method: ' . $method;
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ private function isAnnotationInClassDocBlock(string $fileContent, string $annota
return false;
}
$docBlock = array_shift($matches['docblock']);
return strpos($docBlock, '@'. $annotation) !== false;
return strpos($docBlock, '@' . $annotation) !== false;
}


Expand Down
8 changes: 4 additions & 4 deletions src/PHPUnit/RerunCommandGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private function getClassAndName(\SimpleXMLElement $attributes): array
}
if (null === $class || null === $name) {
throw new \RuntimeException(
'Failed finding the class and/or name in the attributes:'.$attributes->__toString()
'Failed finding the class and/or name in the attributes:' . $attributes->__toString()
);
}

Expand All @@ -94,7 +94,7 @@ private function getFailureNodes(string $contents): array

$nodes = $this->simpleXml->xpath(
'//testsuite/testcase[error] | //testsuite/testcase[failure] '
.'| //testsuite/testcase[skipped] | //testsuite/testcase[incomplete]'
. '| //testsuite/testcase[skipped] | //testsuite/testcase[incomplete]'
);
if (false === $nodes) {
return [];
Expand All @@ -112,7 +112,7 @@ private function load(string $contents): void
if (false === $sXml) {
$message = "Failed loading XML\n";
foreach (libxml_get_errors() as $error) {
$message .= "\n\t".$error->message;
$message .= "\n\t" . $error->message;
}
throw new \RuntimeException($message);
}
Expand All @@ -126,6 +126,6 @@ private function load(string $contents): void
*/
private function getDefaultFilePath(): string
{
return Helper::getProjectRootDirectory().'/var/qa/phpunit.junit.log.xml';
return Helper::getProjectRootDirectory() . '/var/qa/phpunit.junit.log.xml';
}
}
7 changes: 3 additions & 4 deletions src/PHPUnit/TestDox/CliTestDoxPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public function startTest(Test $test): void
$className = $class;
$testMethod = $test->getName();
} else {

return;
}

Expand Down Expand Up @@ -131,8 +130,8 @@ public function addError(Test $test, \Throwable $t, float $time): void
{
if (null === $this->currentTestResult) {
throw new \RuntimeException(
'Error in '.__METHOD__.': '
.$t->getMessage()."\n\n".$t->getTraceAsString(),
'Error in ' . __METHOD__ . ': '
. $t->getMessage() . "\n\n" . $t->getTraceAsString(),
$t->getCode(),
$t
);
Expand Down Expand Up @@ -205,7 +204,7 @@ public function printResult(TestResult $result): void

protected function printHeader(): void
{
$this->write("\n".Timer::resourceUsage()."\n\n");
$this->write("\n" . Timer::resourceUsage() . "\n\n");
}

private function printNonSuccessfulTestsSummary(int $numberOfExecutedTests): void
Expand Down
4 changes: 2 additions & 2 deletions src/PHPUnit/TestDox/TestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function fail(
): void {
$this->testSuccesful = false;
$this->symbol = $symbol;
$this->additionalInformation .= "\n".$additionalInformation;
$this->additionalInformation .= "\n" . $additionalInformation;
$this->additionalInformationVerbose = $additionalInformationVerbose;
}

Expand All @@ -94,7 +94,7 @@ public function toString(?self $previousTestResult, bool $verbose = false): stri
),
$this->symbol,
$this->testMethod,
$verbose ? ' '.$this->getFormattedRuntime() : '',
$verbose ? ' ' . $this->getFormattedRuntime() : '',
$this->getFormattedAdditionalInformation($verbose)
);
}
Expand Down
12 changes: 5 additions & 7 deletions src/Psr4Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ private function expectedFileNamespace(string $absPathRoot, string $namespaceRoo
);
}

return rtrim($namespaceRoot.$relativeNs, '\\');
return rtrim($namespaceRoot . $relativeNs, '\\');
}

private function getActualNamespace(\SplFileInfo $fileInfo): string
{
$contents = \file_get_contents($fileInfo->getPathname());
if (false === $contents) {
throw new \RuntimeException('Failed getting file contents for '.$fileInfo->getPathname());
throw new \RuntimeException('Failed getting file contents for ' . $fileInfo->getPathname());
}
\preg_match('%namespace\s+?([^;]+)%', $contents, $matches);
if ([] === $matches) {
Expand Down Expand Up @@ -175,12 +175,10 @@ protected function compare($item1, $item2): int

private function addMissingPathError(string $path, string $namespaceRoot, string $absPathRoot): void
{
$invalidPathMessage = "Namespace root '$namespaceRoot'".
"\ncontains a path '$path''".
"\nwhich doesn't exist\n";
$invalidPathMessage = "Namespace root '$namespaceRoot'\ncontains a path '$path'\nwhich doesn't exist\n";
if (stripos($absPathRoot, "Magento") !== false) {
$invalidPathMessage .= 'Magento\'s composer includes this by default, '
.'it should be removed from the psr-4 section';
. 'it should be removed from the psr-4 section';
}
$this->missingPaths[$path] = $invalidPathMessage;
}
Expand All @@ -204,7 +202,7 @@ private function yieldPhpFilesToCheck(): \Generator
$paths = [$paths];
}
foreach ($paths as $path) {
$absPathRoot = $this->pathToProjectRoot.'/'.$path;
$absPathRoot = $this->pathToProjectRoot . '/' . $path;
$realAbsPathRoot = \realpath($absPathRoot);
if (false === $realAbsPathRoot) {
$this->addMissingPathError($path, $namespaceRoot, $absPathRoot);
Expand Down
4 changes: 2 additions & 2 deletions tests/Small/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testItCanGetComposerJsonDecode(): void
public function testItWillThrowExceptionForInvalidComposerJson(): void
{
$this->expectException(\RuntimeException::class);
Helper::getComposerJsonDecoded(__DIR__.'/../assets/helper/invalid.composer.json');
Helper::getComposerJsonDecoded(__DIR__ . '/../assets/helper/invalid.composer.json');
}

/**
Expand All @@ -44,7 +44,7 @@ public function testItWillThrowExceptionForInvalidComposerJson(): void
*/
public function testGetProjectRoot(): void
{
$expected = \realpath(__DIR__.'/../../../phpqa/');
$expected = \realpath(__DIR__ . '/../../../phpqa/');
$actual = Helper::getProjectRootDirectory();
self::assertSame($expected, $actual);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Small/Markdown/LinksCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LinksCheckerTest extends TestCase
*/
public function testInvalidProject(): void
{
$pathToProject = __DIR__.'/../../assets/linksChecker/projectWithBrokenLinks';
$pathToProject = __DIR__ . '/../../assets/linksChecker/projectWithBrokenLinks';
$expectedExitCode = 1;
$expectedOutput = '
/docs/linksCheckerTest.md
Expand All @@ -47,7 +47,7 @@ public function testInvalidProject(): void
public function testMainNoReadmeFile(): void
{
$this->expectException(\RuntimeException::class);
LinksChecker::main(__DIR__.'/../../assets/linksChecker/projectNoReadme');
LinksChecker::main(__DIR__ . '/../../assets/linksChecker/projectNoReadme');
}

/**
Expand All @@ -57,7 +57,7 @@ public function testMainNoReadmeFile(): void
*/
public function testValidNoDocsFolder(): void
{
$pathToProject = __DIR__.'/../../assets/linksChecker/projectWithReadmeNoDocsFolder';
$pathToProject = __DIR__ . '/../../assets/linksChecker/projectWithReadmeNoDocsFolder';
$expectedExitCode = 0;
$expectedOutput = '';
self::assertResult($pathToProject, $expectedExitCode, $expectedOutput);
Expand All @@ -69,7 +69,7 @@ public function testValidNoDocsFolder(): void
*/
public function testItHandlesNonFileLinks(): void
{
$pathToProject = __DIR__.'/../../assets/linksChecker/projectWithNonFileLinks';
$pathToProject = __DIR__ . '/../../assets/linksChecker/projectWithNonFileLinks';
$expectedExitCode = 1;
$expectedOutput = '
/README.md
Expand Down
10 changes: 5 additions & 5 deletions tests/Small/PHPUnit/CheckAnnotationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function itThrowAnExceptionIfTestsPathIsInvalid(): void
*/
public function itReturnsNoErrorsIfItsAllGood(): void
{
$pathToTestsDirectory = __DIR__.'/../../assets/phpunitAnnotations/projectAllGood/tests';
$pathToTestsDirectory = __DIR__ . '/../../assets/phpunitAnnotations/projectAllGood/tests';
$expected = [];
$actual = $this->checker->main($pathToTestsDirectory);
self::assertSame($expected, $actual);
Expand All @@ -55,7 +55,7 @@ public function itReturnsNoErrorsIfItsAllGood(): void
*/
public function itFindsMissingSmallAnnotations(): void
{
$pathToTestsDirectory = __DIR__.'/../../assets/phpunitAnnotations/projectMissingSmall/tests';
$pathToTestsDirectory = __DIR__ . '/../../assets/phpunitAnnotations/projectMissingSmall/tests';
$expected = [
'SomethingTest.php' => [
'Failed finding @small for method: itDoesSomething',
Expand All @@ -72,7 +72,7 @@ public function itFindsMissingSmallAnnotations(): void
*/
public function itFindsMissingMediumAnnotations(): void
{
$pathToTestsDirectory = __DIR__.'/../../assets/phpunitAnnotations/projectMissingMedium/tests';
$pathToTestsDirectory = __DIR__ . '/../../assets/phpunitAnnotations/projectMissingMedium/tests';
$expected = [
'SomethingTest.php' => [
'Failed finding @medium for method: itDoesSomething',
Expand All @@ -89,7 +89,7 @@ public function itFindsMissingMediumAnnotations(): void
*/
public function itFindsMissingLargeAnnotations(): void
{
$pathToTestsDirectory = __DIR__.'/../../assets/phpunitAnnotations/projectMissingLarge/tests';
$pathToTestsDirectory = __DIR__ . '/../../assets/phpunitAnnotations/projectMissingLarge/tests';
$expected = [
'SomethingTest.php' => [
'Failed finding @large for method: itDoesSomething',
Expand All @@ -107,7 +107,7 @@ public function itFindsMissingLargeAnnotations(): void
*/
public function itReturnsNoErrorsIfNotApplicableToProject(): void
{
$pathToTestsDirectory = __DIR__.'/../../assets/phpunitAnnotations/projectNotApplicable/tests';
$pathToTestsDirectory = __DIR__ . '/../../assets/phpunitAnnotations/projectNotApplicable/tests';
$expected = [];
$actual = $this->checker->main($pathToTestsDirectory);
self::assertSame($expected, $actual);
Expand Down
Loading