-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aac0858
commit 5ef5033
Showing
4 changed files
with
126 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...s/Sniffs/NamingConventions/ElementNameMinimalLength/ElementNameMinimalLengthSniffTest.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |