Skip to content

Commit 15c1c3c

Browse files
💄 Typeint
1 parent 2430199 commit 15c1c3c

17 files changed

+50
-52
lines changed

SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ protected function processParams(
269269
*
270270
* @return bool True if the return does not return anything
271271
*/
272-
protected function isMatchingReturn($tokens, $returnPos)
272+
protected function isMatchingReturn(array $tokens, $returnPos)
273273
{
274274
do {
275275
$returnPos++;

TwigCS/Command/TwigCSCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function configure()
3434
'e',
3535
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
3636
'Excludes, based on regex, paths of files and folders from parsing',
37-
[]
37+
['vendor/']
3838
),
3939
new InputOption(
4040
'level',

TwigCS/Config/Config.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Config
1616
* @var array
1717
*/
1818
public static $defaultConfig = [
19-
'exclude' => ['vendor/'],
19+
'exclude' => [],
2020
'pattern' => '*.twig',
2121
'paths' => [],
2222
'workingDirectory' => '',
@@ -29,14 +29,12 @@ class Config
2929
*/
3030
protected $config;
3131

32-
public function __construct()
32+
/**
33+
* @param array $config
34+
*/
35+
public function __construct(array $config = [])
3336
{
34-
$args = func_get_args();
35-
36-
$this->config = $this::$defaultConfig;
37-
foreach ($args as $arg) {
38-
$this->config = array_merge($this->config, $arg);
39-
}
37+
$this->config = array_merge($this::$defaultConfig, $config);
4038
}
4139

4240
/**
@@ -67,7 +65,7 @@ public function findFiles()
6765
$files->exclude($exclude);
6866
}
6967

70-
return $files;
68+
return iterator_to_array($files, false);
7169
}
7270

7371
/**
@@ -79,7 +77,7 @@ public function findFiles()
7977
*
8078
* @throws Exception
8179
*/
82-
public function get($key)
80+
public function get(string $key)
8381
{
8482
if (!isset($this->config[$key])) {
8583
throw new Exception(sprintf('Configuration key "%s" does not exist', $key));

TwigCS/Linter.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace TwigCS;
44

55
use \Exception;
6-
use \Traversable;
76
use Twig\Environment;
87
use Twig\Error\Error;
98
use Twig\Source;
@@ -42,19 +41,15 @@ public function __construct(Environment $env, Tokenizer $tokenizer)
4241
/**
4342
* Run the linter on the given $files against the given $ruleset.
4443
*
45-
* @param array|string $files List of files to process.
46-
* @param Ruleset $ruleset Set of rules to check.
44+
* @param array $files List of files to process.
45+
* @param Ruleset $ruleset Set of rules to check.
4746
*
4847
* @return Report an object with all violations and stats.
4948
*
5049
* @throws Exception
5150
*/
52-
public function run($files, Ruleset $ruleset)
51+
public function run(array $files, Ruleset $ruleset)
5352
{
54-
if (!is_array($files) && !$files instanceof Traversable) {
55-
$files = [$files];
56-
}
57-
5853
if (empty($files)) {
5954
throw new Exception('No files to process, provide at least one file to be linted');
6055
}
@@ -91,7 +86,7 @@ public function run($files, Ruleset $ruleset)
9186
*
9287
* @return bool
9388
*/
94-
public function processTemplate($file, $ruleset, $report)
89+
public function processTemplate(string $file, Ruleset $ruleset, Report $report)
9590
{
9691
$twigSource = new Source(file_get_contents($file), $file, $file);
9792

@@ -118,7 +113,7 @@ public function processTemplate($file, $ruleset, $report)
118113
$sniffViolation = new SniffViolation(
119114
SniffInterface::MESSAGE_TYPE_ERROR,
120115
sprintf('Unable to tokenize file'),
121-
(string) $file
116+
$file
122117
);
123118

124119
$report->addMessage($sniffViolation);
@@ -141,7 +136,7 @@ public function processTemplate($file, $ruleset, $report)
141136
* @param Report $report
142137
* @param string|null $file
143138
*/
144-
protected function setErrorHandler(Report $report, $file = null)
139+
protected function setErrorHandler(Report $report, string $file = null)
145140
{
146141
set_error_handler(function ($type, $message) use ($report, $file) {
147142
if (E_USER_DEPRECATED === $type) {

TwigCS/Report/Report.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function addMessage(SniffViolation $sniffViolation)
7575
*
7676
* @return SniffViolation[]
7777
*/
78-
public function getMessages($filters = [])
78+
public function getMessages(array $filters = [])
7979
{
8080
if (empty($filters)) {
8181
// Return all messages, without filtering.
@@ -100,7 +100,7 @@ public function getMessages($filters = [])
100100
/**
101101
* @param string $file
102102
*/
103-
public function addFile($file)
103+
public function addFile(string $file)
104104
{
105105
$this->files[] = $file;
106106
}

TwigCS/Report/SniffViolation.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SniffViolation
5757
* @param string $filename
5858
* @param int|null $line
5959
*/
60-
public function __construct($level, $message, $filename, $line = null)
60+
public function __construct(int $level, string $message, string $filename, int $line = null)
6161
{
6262
$this->level = $level;
6363
$this->message = $message;
@@ -99,11 +99,11 @@ public function getLevelAsString()
9999
/**
100100
* Get the integer value for a given string $level.
101101
*
102-
* @param int $level
102+
* @param string $level
103103
*
104104
* @return int
105105
*/
106-
public static function getLevelAsInt($level)
106+
public static function getLevelAsInt(string $level)
107107
{
108108
switch (strtoupper($level)) {
109109
case 'NOTICE':
@@ -143,7 +143,7 @@ public function getLine()
143143
*/
144144
public function getFilename()
145145
{
146-
return (string) $this->filename;
146+
return $this->filename;
147147
}
148148

149149
/**
@@ -153,7 +153,7 @@ public function getFilename()
153153
*
154154
* @return self
155155
*/
156-
public function setLinePosition($linePosition)
156+
public function setLinePosition(int $linePosition)
157157
{
158158
$this->linePosition = $linePosition;
159159

TwigCS/Report/TextFormatter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TextFormatter
2929
* @param InputInterface $input
3030
* @param OutputInterface $output
3131
*/
32-
public function __construct($input, $output)
32+
public function __construct(InputInterface $input, OutputInterface $output)
3333
{
3434
$this->io = new SymfonyStyle($input, $output);
3535
}
@@ -38,7 +38,7 @@ public function __construct($input, $output)
3838
* @param Report $report
3939
* @param string|null $level
4040
*/
41-
public function display(Report $report, $level = null)
41+
public function display(Report $report, string $level = null)
4242
{
4343
foreach ($report->getFiles() as $file) {
4444
$fileMessages = $report->getMessages([
@@ -106,7 +106,7 @@ public function display(Report $report, $level = null)
106106
*
107107
* @return array
108108
*/
109-
protected function getContext($template, $line, $context)
109+
protected function getContext(string $template, int $line, int $context)
110110
{
111111
$lines = explode("\n", $template);
112112

TwigCS/Ruleset/Generic/BlankEOFSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BlankEOFSniff extends AbstractSniff
2020
*
2121
* @throws Exception
2222
*/
23-
public function process(Token $token, $tokenPosition, $tokens)
23+
public function process(Token $token, int $tokenPosition, array $tokens)
2424
{
2525
if ($this->isTokenMatching($token, Token::EOF_TYPE)) {
2626
$i = 0;

TwigCS/Ruleset/Generic/DelimiterSpacingSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DelimiterSpacingSniff extends AbstractSniff
2020
*
2121
* @throws Exception
2222
*/
23-
public function process(Token $token, $tokenPosition, $tokens)
23+
public function process(Token $token, int $tokenPosition, array $tokens)
2424
{
2525
if ($this->isTokenMatching($token, Token::VAR_START_TYPE)
2626
|| $this->isTokenMatching($token, Token::BLOCK_START_TYPE)

TwigCS/Ruleset/Generic/DisallowCommentedCodeSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DisallowCommentedCodeSniff extends AbstractSniff
2222
*
2323
* @throws Exception
2424
*/
25-
public function process(Token $token, $tokenPosition, $tokens)
25+
public function process(Token $token, int $tokenPosition, array $tokens)
2626
{
2727
if ($this->isTokenMatching($token, Token::COMMENT_START_TYPE)) {
2828
$i = $tokenPosition;

0 commit comments

Comments
 (0)