Skip to content

Commit 726e80e

Browse files
minor #42118 [Yaml] Add types to private properties (derrabus)
This PR was merged into the 6.0 branch. Discussion ---------- [Yaml] Add types to private properties | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A Commits ------- 40688504ac [Yaml] Add types to private properties
2 parents 0e271d5 + c64b254 commit 726e80e

File tree

5 files changed

+32
-36
lines changed

5 files changed

+32
-36
lines changed

Command/LintCommand.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ class LintCommand extends Command
3535
protected static $defaultName = 'lint:yaml';
3636
protected static $defaultDescription = 'Lint a YAML file and outputs encountered errors';
3737

38-
private $parser;
39-
private $format;
40-
private $displayCorrectFiles;
41-
private $directoryIteratorProvider;
42-
private $isReadableProvider;
38+
private Parser $parser;
39+
private ?string $format = null;
40+
private bool $displayCorrectFiles;
41+
private ?\Closure $directoryIteratorProvider;
42+
private ?\Closure $isReadableProvider;
4343

4444
public function __construct(string $name = null, callable $directoryIteratorProvider = null, callable $isReadableProvider = null)
4545
{
4646
parent::__construct($name);
4747

48-
$this->directoryIteratorProvider = $directoryIteratorProvider;
49-
$this->isReadableProvider = $isReadableProvider;
48+
$this->directoryIteratorProvider = null === $directoryIteratorProvider || $directoryIteratorProvider instanceof \Closure ? $directoryIteratorProvider : \Closure::fromCallable($directoryIteratorProvider);
49+
$this->isReadableProvider = null === $isReadableProvider || $isReadableProvider instanceof \Closure ? $isReadableProvider : \Closure::fromCallable($isReadableProvider);
5050
}
5151

5252
/**
@@ -232,11 +232,7 @@ private function getFiles(string $fileOrDirectory): iterable
232232

233233
private function getParser(): Parser
234234
{
235-
if (!$this->parser) {
236-
$this->parser = new Parser();
237-
}
238-
239-
return $this->parser;
235+
return $this->parser ??= new Parser();
240236
}
241237

242238
private function getDirectoryIterator(string $directory): iterable

Exception/ParseException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
*/
1919
class ParseException extends RuntimeException
2020
{
21-
private $parsedFile;
22-
private $parsedLine;
23-
private $snippet;
24-
private $rawMessage;
21+
private ?string $parsedFile;
22+
private int $parsedLine;
23+
private ?string $snippet;
24+
private string $rawMessage;
2525

2626
/**
2727
* @param string $message The error message

Inline.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class Inline
2929
public static $parsedLineNumber = -1;
3030
public static $parsedFilename;
3131

32-
private static $exceptionOnInvalidType = false;
33-
private static $objectSupport = false;
34-
private static $objectForMap = false;
35-
private static $constantSupport = false;
32+
private static bool $exceptionOnInvalidType = false;
33+
private static bool $objectSupport = false;
34+
private static bool $objectForMap = false;
35+
private static bool $constantSupport = false;
3636

3737
public static function initialize(int $flags, int $parsedLineNumber = null, string $parsedFilename = null)
3838
{
@@ -50,9 +50,9 @@ public static function initialize(int $flags, int $parsedLineNumber = null, stri
5050
/**
5151
* Converts a YAML string to a PHP value.
5252
*
53-
* @param string $value A YAML string
54-
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
55-
* @param array $references Mapping of variable names to values
53+
* @param string|null $value A YAML string
54+
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
55+
* @param array $references Mapping of variable names to values
5656
*
5757
* @throws ParseException
5858
*/

Parser.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ class Parser
2727
public const BLOCK_SCALAR_HEADER_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?';
2828
public const REFERENCE_PATTERN = '#^&(?P<ref>[^ ]++) *+(?P<value>.*)#u';
2929

30-
private $filename;
31-
private $offset = 0;
32-
private $numberOfParsedLines = 0;
33-
private $totalNumberOfLines;
34-
private $lines = [];
35-
private $currentLineNb = -1;
36-
private $currentLine = '';
37-
private $refs = [];
38-
private $skippedLineNumbers = [];
39-
private $locallySkippedLineNumbers = [];
40-
private $refsBeingParsed = [];
30+
private ?string $filename = null;
31+
private int $offset = 0;
32+
private int $numberOfParsedLines = 0;
33+
private ?int $totalNumberOfLines = null;
34+
private array $lines = [];
35+
private int $currentLineNb = -1;
36+
private string $currentLine = '';
37+
private array $refs = [];
38+
private array $skippedLineNumbers = [];
39+
private array $locallySkippedLineNumbers = [];
40+
private array $refsBeingParsed = [];
4141

4242
/**
4343
* Parses a YAML file into a PHP value.

Tag/TaggedValue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818
final class TaggedValue
1919
{
20-
private $tag;
21-
private $value;
20+
private string $tag;
21+
private mixed $value;
2222

2323
public function __construct(string $tag, mixed $value)
2424
{

0 commit comments

Comments
 (0)