Skip to content

Commit 8974f26

Browse files
committed
CS: always import all used classes [1]
... instead of using fully qualified global/PHP native classes inline.
1 parent 3756f11 commit 8974f26

24 files changed

+105
-55
lines changed

src/Config.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace PHP_CodeSniffer;
1414

15+
use Exception;
16+
use Phar;
1517
use PHP_CodeSniffer\Exceptions\DeepExitException;
1618
use PHP_CodeSniffer\Exceptions\RuntimeException;
1719
use PHP_CodeSniffer\Util\Common;
@@ -812,7 +814,7 @@ public function processLongArgument($arg, $pos)
812814

813815
try {
814816
$this->setConfigData($key, $value);
815-
} catch (\Exception $e) {
817+
} catch (Exception $e) {
816818
throw new DeepExitException($e->getMessage().PHP_EOL, 3);
817819
}
818820

@@ -840,7 +842,7 @@ public function processLongArgument($arg, $pos)
840842
} else {
841843
try {
842844
$this->setConfigData($key, null);
843-
} catch (\Exception $e) {
845+
} catch (Exception $e) {
844846
throw new DeepExitException($e->getMessage().PHP_EOL, 3);
845847
}
846848

@@ -1608,7 +1610,7 @@ public static function setConfigData($key, $value, $temp=false)
16081610
if ($temp === false) {
16091611
$path = '';
16101612
if (is_callable('\Phar::running') === true) {
1611-
$path = \Phar::running(false);
1613+
$path = Phar::running(false);
16121614
}
16131615

16141616
if ($path !== '') {
@@ -1679,7 +1681,7 @@ public static function getAllConfigData()
16791681

16801682
$path = '';
16811683
if (is_callable('\Phar::running') === true) {
1682-
$path = \Phar::running(false);
1684+
$path = Phar::running(false);
16831685
}
16841686

16851687
if ($path !== '') {

src/Exceptions/DeepExitException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
namespace PHP_CodeSniffer\Exceptions;
1414

15-
class DeepExitException extends \Exception
15+
use Exception;
16+
17+
class DeepExitException extends Exception
1618
{
1719

1820
}//end class

src/Exceptions/RuntimeException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace PHP_CodeSniffer\Exceptions;
1111

12-
class RuntimeException extends \RuntimeException
12+
use RuntimeException as PHPRuntimeException;
13+
14+
class RuntimeException extends PHPRuntimeException
1315
{
1416

1517
}//end class

src/Exceptions/TokenizerException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace PHP_CodeSniffer\Exceptions;
1111

12-
class TokenizerException extends \Exception
12+
use Exception;
13+
14+
class TokenizerException extends Exception
1315
{
1416

1517
}//end class

src/Files/FileList.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@
1111

1212
namespace PHP_CodeSniffer\Files;
1313

14+
use Countable;
15+
use FilesystemIterator;
16+
use Iterator;
1417
use PHP_CodeSniffer\Autoload;
1518
use PHP_CodeSniffer\Config;
1619
use PHP_CodeSniffer\Exceptions\DeepExitException;
1720
use PHP_CodeSniffer\Ruleset;
1821
use PHP_CodeSniffer\Util;
22+
use RecursiveArrayIterator;
23+
use RecursiveDirectoryIterator;
24+
use RecursiveIteratorIterator;
1925
use ReturnTypeWillChange;
2026

21-
class FileList implements \Iterator, \Countable
27+
class FileList implements Iterator, Countable
2228
{
2329

2430
/**
@@ -80,9 +86,9 @@ public function __construct(Config $config, Ruleset $ruleset)
8086

8187
$filterClass = $this->getFilterClass();
8288

83-
$di = new \RecursiveDirectoryIterator($path, (\RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS));
89+
$di = new RecursiveDirectoryIterator($path, (RecursiveDirectoryIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS));
8490
$filter = new $filterClass($di, $path, $config, $ruleset);
85-
$iterator = new \RecursiveIteratorIterator($filter);
91+
$iterator = new RecursiveIteratorIterator($filter);
8692

8793
foreach ($iterator as $file) {
8894
$this->files[$file->getPathname()] = null;
@@ -121,9 +127,9 @@ public function addFile($path, $file=null)
121127

122128
$filterClass = $this->getFilterClass();
123129

124-
$di = new \RecursiveArrayIterator([$path]);
130+
$di = new RecursiveArrayIterator([$path]);
125131
$filter = new $filterClass($di, $path, $this->config, $this->ruleset);
126-
$iterator = new \RecursiveIteratorIterator($filter);
132+
$iterator = new RecursiveIteratorIterator($filter);
127133

128134
foreach ($iterator as $path) {
129135
$this->files[$path] = $file;

src/Filters/Filter.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99

1010
namespace PHP_CodeSniffer\Filters;
1111

12+
use FilesystemIterator;
1213
use PHP_CodeSniffer\Config;
1314
use PHP_CodeSniffer\Ruleset;
1415
use PHP_CodeSniffer\Util;
16+
use RecursiveDirectoryIterator;
17+
use RecursiveFilterIterator;
1518
use ReturnTypeWillChange;
1619

17-
class Filter extends \RecursiveFilterIterator
20+
class Filter extends RecursiveFilterIterator
1821
{
1922

2023
/**
@@ -137,7 +140,7 @@ public function getChildren()
137140
{
138141
$filterClass = get_called_class();
139142
$children = new $filterClass(
140-
new \RecursiveDirectoryIterator($this->current(), (\RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS)),
143+
new RecursiveDirectoryIterator($this->current(), (RecursiveDirectoryIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS)),
141144
$this->basedir,
142145
$this->config,
143146
$this->ruleset

src/Generators/Generator.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace PHP_CodeSniffer\Generators;
1414

15+
use DOMDocument;
16+
use DOMNode;
1517
use PHP_CodeSniffer\Autoload;
1618
use PHP_CodeSniffer\Ruleset;
1719

@@ -70,7 +72,7 @@ public function __construct(Ruleset $ruleset)
7072
*
7173
* @return string
7274
*/
73-
protected function getTitle(\DOMNode $doc)
75+
protected function getTitle(DOMNode $doc)
7476
{
7577
return $doc->getAttribute('title');
7678

@@ -90,7 +92,7 @@ protected function getTitle(\DOMNode $doc)
9092
public function generate()
9193
{
9294
foreach ($this->docFiles as $file) {
93-
$doc = new \DOMDocument();
95+
$doc = new DOMDocument();
9496
$doc->load($file);
9597
$documentation = $doc->getElementsByTagName('documentation')->item(0);
9698
$this->processSniff($documentation);
@@ -111,7 +113,7 @@ public function generate()
111113
* @return void
112114
* @see generate()
113115
*/
114-
abstract protected function processSniff(\DOMNode $doc);
116+
abstract protected function processSniff(DOMNode $doc);
115117

116118

117119
}//end class

src/Generators/HTML.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace PHP_CodeSniffer\Generators;
1515

16+
use DOMDocument;
17+
use DOMNode;
1618
use PHP_CodeSniffer\Config;
1719

1820
class HTML extends Generator
@@ -32,7 +34,7 @@ public function generate()
3234
$this->printToc();
3335

3436
foreach ($this->docFiles as $file) {
35-
$doc = new \DOMDocument();
37+
$doc = new DOMDocument();
3638
$doc->load($file);
3739
$documentation = $doc->getElementsByTagName('documentation')->item(0);
3840
$this->processSniff($documentation);
@@ -145,7 +147,7 @@ protected function printToc()
145147
echo ' <ul class="toc">'.PHP_EOL;
146148

147149
foreach ($this->docFiles as $file) {
148-
$doc = new \DOMDocument();
150+
$doc = new DOMDocument();
149151
$doc->load($file);
150152
$documentation = $doc->getElementsByTagName('documentation')->item(0);
151153
$title = $this->getTitle($documentation);
@@ -188,7 +190,7 @@ protected function printFooter()
188190
*
189191
* @return void
190192
*/
191-
public function processSniff(\DOMNode $doc)
193+
public function processSniff(DOMNode $doc)
192194
{
193195
$title = $this->getTitle($doc);
194196
echo ' <a name="'.str_replace(' ', '-', $title).'" />'.PHP_EOL;
@@ -212,7 +214,7 @@ public function processSniff(\DOMNode $doc)
212214
*
213215
* @return void
214216
*/
215-
protected function printTextBlock(\DOMNode $node)
217+
protected function printTextBlock(DOMNode $node)
216218
{
217219
$content = trim($node->nodeValue);
218220
$content = htmlspecialchars($content);
@@ -233,7 +235,7 @@ protected function printTextBlock(\DOMNode $node)
233235
*
234236
* @return void
235237
*/
236-
protected function printCodeComparisonBlock(\DOMNode $node)
238+
protected function printCodeComparisonBlock(DOMNode $node)
237239
{
238240
$codeBlocks = $node->getElementsByTagName('code');
239241

src/Generators/Markdown.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace PHP_CodeSniffer\Generators;
1111

12+
use DOMDocument;
13+
use DOMNode;
1214
use PHP_CodeSniffer\Config;
1315

1416
class Markdown extends Generator
@@ -27,7 +29,7 @@ public function generate()
2729
$this->printHeader();
2830

2931
foreach ($this->docFiles as $file) {
30-
$doc = new \DOMDocument();
32+
$doc = new DOMDocument();
3133
$doc->load($file);
3234
$documentation = $doc->getElementsByTagName('documentation')->item(0);
3335
$this->processSniff($documentation);
@@ -81,7 +83,7 @@ protected function printFooter()
8183
*
8284
* @return void
8385
*/
84-
protected function processSniff(\DOMNode $doc)
86+
protected function processSniff(DOMNode $doc)
8587
{
8688
$title = $this->getTitle($doc);
8789
echo PHP_EOL."## $title".PHP_EOL;
@@ -104,7 +106,7 @@ protected function processSniff(\DOMNode $doc)
104106
*
105107
* @return void
106108
*/
107-
protected function printTextBlock(\DOMNode $node)
109+
protected function printTextBlock(DOMNode $node)
108110
{
109111
$content = trim($node->nodeValue);
110112
$content = htmlspecialchars($content);
@@ -124,7 +126,7 @@ protected function printTextBlock(\DOMNode $node)
124126
*
125127
* @return void
126128
*/
127-
protected function printCodeComparisonBlock(\DOMNode $node)
129+
protected function printCodeComparisonBlock(DOMNode $node)
128130
{
129131
$codeBlocks = $node->getElementsByTagName('code');
130132

src/Generators/Text.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace PHP_CodeSniffer\Generators;
1313

14+
use DOMNode;
15+
1416
class Text extends Generator
1517
{
1618

@@ -24,7 +26,7 @@ class Text extends Generator
2426
*
2527
* @return void
2628
*/
27-
public function processSniff(\DOMNode $doc)
29+
public function processSniff(DOMNode $doc)
2830
{
2931
$this->printTitle($doc);
3032

@@ -48,7 +50,7 @@ public function processSniff(\DOMNode $doc)
4850
*
4951
* @return void
5052
*/
51-
protected function printTitle(\DOMNode $doc)
53+
protected function printTitle(DOMNode $doc)
5254
{
5355
$title = $this->getTitle($doc);
5456
$standard = $this->ruleset->name;
@@ -69,7 +71,7 @@ protected function printTitle(\DOMNode $doc)
6971
*
7072
* @return void
7173
*/
72-
protected function printTextBlock(\DOMNode $node)
74+
protected function printTextBlock(DOMNode $node)
7375
{
7476
$text = trim($node->nodeValue);
7577
$text = str_replace('<em>', '*', $text);
@@ -123,7 +125,7 @@ protected function printTextBlock(\DOMNode $node)
123125
*
124126
* @return void
125127
*/
126-
protected function printCodeComparisonBlock(\DOMNode $node)
128+
protected function printCodeComparisonBlock(DOMNode $node)
127129
{
128130
$codeBlocks = $node->getElementsByTagName('code');
129131
$first = trim($codeBlocks->item(0)->nodeValue);

0 commit comments

Comments
 (0)