Skip to content

Commit

Permalink
test and cs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 17, 2017
1 parent aac0858 commit 5ef5033
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 5 deletions.
4 changes: 0 additions & 4 deletions easy-coding-standard.neon
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ checkers:
- Symplify\CodingStandard\Sniffs\Namespaces\ClassNamesWithoutPreSlashSniff

- PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer
- PhpCsFixer\Fixer\NamespaceNotation\BlankLineAfterNamespaceFixer

# Symplify: Naming
- Symplify\CodingStandard\Sniffs\Naming\AbstractClassNameSniff
Expand Down Expand Up @@ -177,7 +176,6 @@ checkers:
- PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer
- PhpCsFixer\Fixer\ControlStructure\ElseifFixer
- PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer
- PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer
- PhpCsFixer\Fixer\Whitespace\IndentationTypeFixer
- PhpCsFixer\Fixer\Whitespace\LineEndingFixer
- PhpCsFixer\Fixer\Casing\LowercaseKeywordsFixer
Expand All @@ -203,8 +201,6 @@ checkers:
PhpCsFixer\Fixer\Basic\BracesFixer:
allow_single_line_closure: true
- PhpCsFixer\Fixer\CastNotation\CastSpacesFixer
PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer:
singleLine: true
- PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer
- PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer
- PhpCsFixer\Fixer\Comment\HashToSlashCommentFixer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function process(File $file, $position): void

private function isSniffClass(File $file, int $position): bool
{
$classTokenPosition = $file->findPrevious(T_CLASS, $position);
$classTokenPosition = (int) $file->findPrevious(T_CLASS, $position);
$classNameTokenPosition = $file->findNext(T_STRING, $classTokenPosition);

$classNameToken = $file->getTokens()[$classNameTokenPosition];
Expand Down
70 changes: 70 additions & 0 deletions tests/FileFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php declare(strict_types=1);

namespace ObjectCalisthenics\Tests;

use PHP_CodeSniffer\Config;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Ruleset;
use PHP_CodeSniffer\Util\Tokens;

final class FileFactory
{
public function __construct()
{
// legacy compatibility
if (! defined('PHP_CODESNIFFER_VERBOSITY')) {
define('PHP_CODESNIFFER_VERBOSITY', 0);
define('PHP_CODESNIFFER_CBF', false);
define('PHP_CODESNIFFER_IN_TESTS', true);
}

// initialize Token constants
if (! defined('T_NONE')) {
new Tokens();
}
}

public function createFile(string $filePath): File
{
$config = $this->createConfig();
$ruleset = new Ruleset($config);

$file = new File($filePath, $ruleset, $config);
$file->setContent(file_get_contents($filePath));
$file->parse();

return $file;
}

public function createFileWithSniffClass(string $filePath, string $sniffClass): File
{
$config = $this->createConfig();
$ruleset = $this->createRulesetWithConfigAndSniffClass($sniffClass, $config);

$file = new File($filePath, $ruleset, $config);
$file->setContent(file_get_contents($filePath));
$file->parse();

return $file;
}

private function createRulesetWithConfigAndSniffClass(string $sniffClass, Config $config): Ruleset
{
$config->sniffs = [$sniffClass];
$config->standards = ['ObjectCalisthenics'];

$ruleset = new Ruleset($config);
// $ruleset->populateTokenListeners();

return $ruleset;
}

private function createConfig(): Config
{
$config = new Config();
// nulling required, because PEAR Standard is on by default
// $config->standards = [];

return $config;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

class Test
{
const BL = '2';

const LONGEST_CONSTANT_NAME_EVER_LONGEST_CONSTANT_NAME_EVER = '2';
}

class ValidClassName
{
public function te()
{
}
}

function te()
{
}

function veryLongFunctionName()
{
}

class Te
{
}

trait Tr
{
}

class Test
{
public $te = 0;

public $veryLongPropertyNameVeryLongPropertyName = 2;

public $id = 3;

public function __construct($t)
{
$this->te = $t;
}

public function testing()
{
$bl = 2;

for ($i = 0; $i < range(0, 9); $i++) {
echo $i;
}
$veryLongPropertyNameVeryLongPropertyName = 3;
}
}

0 comments on commit 5ef5033

Please sign in to comment.