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;

TwigCS/Ruleset/Ruleset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function addSniff(SniffInterface $sniff)
5151
*
5252
* @throws Exception
5353
*/
54-
public function addStandard($standardName = 'Generic')
54+
public function addStandard(string $standardName = 'Generic')
5555
{
5656
try {
5757
$finder = Finder::create()->in(__DIR__.'/'.$standardName)->files();

TwigCS/Sniff/AbstractSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function getReport()
7575
*
7676
* @return bool
7777
*/
78-
public function isTokenMatching(Token $token, $type, $value = null)
78+
public function isTokenMatching(Token $token, int $type, string $value = null)
7979
{
8080
return $token->getType() === $type && (null === $value || $token->getValue() === $value);
8181
}
@@ -91,7 +91,7 @@ public function isTokenMatching(Token $token, $type, $value = null)
9191
*
9292
* @throws Exception
9393
*/
94-
public function addMessage($messageType, $message, Token $token)
94+
public function addMessage(int $messageType, string $message, Token $token)
9595
{
9696
$sniffViolation = new SniffViolation(
9797
$messageType,
@@ -111,7 +111,7 @@ public function addMessage($messageType, $message, Token $token)
111111
*
112112
* @return string
113113
*/
114-
public function stringifyValue($token)
114+
public function stringifyValue(Token $token)
115115
{
116116
if ($token->getType() === Token::STRING_TYPE) {
117117
return $token->getValue();

TwigCS/Sniff/SniffInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ public function getReport();
5050
* @param int $tokenPosition
5151
* @param Token[] $stream
5252
*/
53-
public function process(Token $token, $tokenPosition, $stream);
53+
public function process(Token $token, int $tokenPosition, array $stream);
5454
}

TwigCS/Tests/AbstractSniffTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function checkGenericSniff(SniffInterface $sniff, array $expects)
5050
$file = __DIR__.'/Fixtures/'.$class->getShortName().'.twig';
5151

5252
$ruleset->addSniff($sniff);
53-
$report = $this->lint->run($file, $ruleset);
53+
$report = $this->lint->run([$file], $ruleset);
5454
} catch (Exception $e) {
5555
$this->fail($e->getMessage());
5656

TwigCS/Token/Token.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ class Token
6363
* @param string $filename
6464
* @param string|null $value
6565
*/
66-
public function __construct($type, $line, $position, $filename, $value = null)
67-
{
66+
public function __construct(
67+
int $type,
68+
int $line,
69+
int $position,
70+
string $filename,
71+
string $value = null
72+
) {
6873
$this->type = $type;
6974
$this->line = $line;
7075
$this->position = $position;

TwigCS/Token/TokenParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class TokenParser extends AbstractTokenParser
2121
/**
2222
* @param string $name
2323
*/
24-
public function __construct($name)
24+
public function __construct(string $name)
2525
{
2626
$this->name = $name;
2727
}

TwigCS/Token/Tokenizer.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected function getState()
190190
/**
191191
* @param int $state
192192
*/
193-
protected function pushState($state)
193+
protected function pushState(int $state)
194194
{
195195
$this->state[] = $state;
196196
}
@@ -209,7 +209,7 @@ protected function popState()
209209
/**
210210
* @param string $code
211211
*/
212-
protected function preflightSource($code)
212+
protected function preflightSource(string $code)
213213
{
214214
$tokenPositions = [];
215215
preg_match_all($this->regexes['lex_tokens_start'], $code, $tokenPositions, PREG_OFFSET_CAPTURE);
@@ -231,7 +231,7 @@ protected function preflightSource($code)
231231
*
232232
* @return array|null
233233
*/
234-
protected function getTokenPosition($offset = 0)
234+
protected function getTokenPosition(int $offset = 0)
235235
{
236236
if (empty($this->tokenPositions)
237237
|| !isset($this->tokenPositions[$this->currentPosition + $offset])
@@ -245,15 +245,15 @@ protected function getTokenPosition($offset = 0)
245245
/**
246246
* @param int $value
247247
*/
248-
protected function moveCurrentPosition($value = 1)
248+
protected function moveCurrentPosition(int $value = 1)
249249
{
250250
$this->currentPosition += $value;
251251
}
252252

253253
/**
254254
* @param string $value
255255
*/
256-
protected function moveCursor($value)
256+
protected function moveCursor(string $value)
257257
{
258258
$this->cursor += strlen($value);
259259
$this->line += substr_count($value, "\n");
@@ -263,7 +263,7 @@ protected function moveCursor($value)
263263
* @param int $type
264264
* @param string|null $value
265265
*/
266-
protected function pushToken($type, $value = null)
266+
protected function pushToken(int $type, string $value = null)
267267
{
268268
$tokenPositionInLine = $this->cursor - strrpos(substr($this->code, 0, $this->cursor), PHP_EOL);
269269
$this->tokens[] = new Token($type, $this->line, $tokenPositionInLine, $this->filename, $value);
@@ -384,7 +384,7 @@ protected function lexComment()
384384
/**
385385
* @param int $limit
386386
*/
387-
protected function lexData($limit = 0)
387+
protected function lexData(int $limit = 0)
388388
{
389389
$nextToken = $this->getTokenPosition();
390390
if (0 === $limit && null !== $nextToken) {

0 commit comments

Comments
 (0)