Skip to content

Commit cc9b7bb

Browse files
authored
Merge pull request #1237 from PHPCSStandards/phpcs-4.x/feature/390-add-param-types
4.0 | Add parameter types to all (non-test) methods
2 parents 695ed86 + a44f026 commit cc9b7bb

File tree

324 files changed

+817
-793
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

324 files changed

+817
-793
lines changed

autoload.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Autoload
6565
*
6666
* @return bool
6767
*/
68-
public static function load($className)
68+
public static function load(string $className)
6969
{
7070
// Include the composer autoloader if there is one, but re-register it
7171
// so this autoloader runs before the composer one as we need to include
@@ -151,7 +151,7 @@ public static function load($className)
151151
*
152152
* @return string The fully qualified name of the class in the loaded file.
153153
*/
154-
public static function loadFile($path)
154+
public static function loadFile(string $path)
155155
{
156156
if (strpos(__DIR__, 'phar://') !== 0) {
157157
$path = realpath($path);
@@ -195,7 +195,7 @@ public static function loadFile($path)
195195
*
196196
* @return string The fully qualified name of the class in the loaded file.
197197
*/
198-
public static function determineLoadedClass($classesBeforeLoad, $classesAfterLoad)
198+
public static function determineLoadedClass(array $classesBeforeLoad, array $classesAfterLoad)
199199
{
200200
$className = null;
201201

@@ -256,7 +256,7 @@ static function ($remaining, $current) {
256256
*
257257
* @return void
258258
*/
259-
public static function addSearchPath($path, $nsPrefix='')
259+
public static function addSearchPath(string $path, string $nsPrefix='')
260260
{
261261
self::$searchPaths[$path] = rtrim(trim((string) $nsPrefix), '\\');
262262

@@ -283,7 +283,7 @@ public static function getSearchPaths()
283283
* @throws \Exception If the file path has not been loaded.
284284
* @return string
285285
*/
286-
public static function getLoadedClassName($path)
286+
public static function getLoadedClassName(string $path)
287287
{
288288
if (isset(self::$loadedClasses[$path]) === false) {
289289
throw new Exception("Cannot get class name for $path; file has not been included");
@@ -302,7 +302,7 @@ public static function getLoadedClassName($path)
302302
* @throws \Exception If the class name has not been loaded.
303303
* @return string
304304
*/
305-
public static function getLoadedFileName($className)
305+
public static function getLoadedFileName(string $className)
306306
{
307307
if (isset(self::$loadedFiles[$className]) === false) {
308308
throw new Exception("Cannot get file name for $className; class has not been included");

scripts/build-phar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*
4747
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException When tokenizer errors are encountered.
4848
*/
49-
function stripWhitespaceAndComments($fullpath, $config)
49+
function stripWhitespaceAndComments(string $fullpath, Config $config)
5050
{
5151
$contents = file_get_contents($fullpath);
5252

src/Config.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class Config
252252
* @return mixed
253253
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the setting name is invalid.
254254
*/
255-
public function __get($name)
255+
public function __get(string $name)
256256
{
257257
if (array_key_exists($name, $this->settings) === false) {
258258
throw new RuntimeException("ERROR: unable to get value of property \"$name\"");
@@ -288,7 +288,7 @@ public function __get($name)
288288
* @return void
289289
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the setting name is invalid.
290290
*/
291-
public function __set($name, $value)
291+
public function __set(string $name, $value)
292292
{
293293
if (array_key_exists($name, $this->settings) === false) {
294294
throw new RuntimeException("Can't __set() $name; setting doesn't exist");
@@ -359,7 +359,7 @@ public function __set($name, $value)
359359
*
360360
* @return bool
361361
*/
362-
public function __isset($name)
362+
public function __isset(string $name)
363363
{
364364
return isset($this->settings[$name]);
365365

@@ -373,7 +373,7 @@ public function __isset($name)
373373
*
374374
* @return void
375375
*/
376-
public function __unset($name)
376+
public function __unset(string $name)
377377
{
378378
$this->settings[$name] = null;
379379

@@ -399,7 +399,7 @@ public function getSettings()
399399
*
400400
* @return void
401401
*/
402-
public function setSettings($settings)
402+
public function setSettings(array $settings)
403403
{
404404
$this->settings = $settings;
405405

@@ -415,7 +415,7 @@ public function setSettings($settings)
415415
*
416416
* @return void
417417
*/
418-
public function __construct(array $cliArgs=[], $dieOnUnknownArg=true)
418+
public function __construct(array $cliArgs=[], bool $dieOnUnknownArg=true)
419419
{
420420
if (defined('PHP_CODESNIFFER_IN_TESTS') === true) {
421421
// Let everything through during testing so that we can
@@ -498,7 +498,7 @@ public function __construct(array $cliArgs=[], $dieOnUnknownArg=true)
498498
*
499499
* @return void
500500
*/
501-
public function setCommandLineValues($args)
501+
public function setCommandLineValues(array $args)
502502
{
503503
$this->cliArgs = $args;
504504
$numArgs = count($args);
@@ -675,7 +675,7 @@ public function restoreDefaults()
675675
* @return void
676676
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
677677
*/
678-
public function processShortArgument($arg, $pos)
678+
public function processShortArgument(string $arg, int $pos)
679679
{
680680
switch ($arg) {
681681
case 'h':
@@ -787,7 +787,7 @@ public function processShortArgument($arg, $pos)
787787
* @return void
788788
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
789789
*/
790-
public function processLongArgument($arg, $pos)
790+
public function processLongArgument(string $arg, int $pos)
791791
{
792792
switch ($arg) {
793793
case 'help':
@@ -1319,7 +1319,7 @@ public function processLongArgument($arg, $pos)
13191319
* @return array<string>
13201320
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException When any of the provided codes are not valid as sniff codes.
13211321
*/
1322-
private function parseSniffCodes($input, $argument)
1322+
private function parseSniffCodes(string $input, string $argument)
13231323
{
13241324
$errors = [];
13251325
$sniffs = [];
@@ -1408,7 +1408,7 @@ static function ($carry, $item) {
14081408
* @return void
14091409
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
14101410
*/
1411-
public function processUnknownArgument($arg, $pos)
1411+
public function processUnknownArgument(string $arg, int $pos)
14121412
{
14131413
// We don't know about any additional switches; just files.
14141414
if ($arg[0] === '-') {
@@ -1434,7 +1434,7 @@ public function processUnknownArgument($arg, $pos)
14341434
* @return void
14351435
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
14361436
*/
1437-
public function processFilePath($path)
1437+
public function processFilePath(string $path)
14381438
{
14391439
// If we are processing STDIN, don't record any files to check.
14401440
if ($this->stdin === true) {
@@ -1490,7 +1490,7 @@ public function printUsage()
14901490
*
14911491
* @return string|void
14921492
*/
1493-
public function printShortUsage($returnOutput=false)
1493+
public function printShortUsage(bool $returnOutput=false)
14941494
{
14951495
if (PHP_CODESNIFFER_CBF === true) {
14961496
$usage = 'Run "phpcbf --help" for usage information';
@@ -1560,7 +1560,7 @@ public function printPHPCBFUsage()
15601560
* @see setConfigData()
15611561
* @see getAllConfigData()
15621562
*/
1563-
public static function getConfigData($key)
1563+
public static function getConfigData(string $key)
15641564
{
15651565
$phpCodeSnifferConfig = self::getAllConfigData();
15661566

@@ -1585,7 +1585,7 @@ public static function getConfigData($key)
15851585
* @return string|null
15861586
* @see getConfigData()
15871587
*/
1588-
public static function getExecutablePath($name)
1588+
public static function getExecutablePath(string $name)
15891589
{
15901590
$data = self::getConfigData($name.'_path');
15911591
if ($data !== null) {
@@ -1633,7 +1633,7 @@ public static function getExecutablePath($name)
16331633
* @see getConfigData()
16341634
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException If the config file can not be written.
16351635
*/
1636-
public function setConfigData($key, $value, $temp=false)
1636+
public function setConfigData(string $key, ?string $value, bool $temp=false)
16371637
{
16381638
if (isset($this->overriddenDefaults['runtime-set']) === true
16391639
&& isset($this->overriddenDefaults['runtime-set'][$key]) === true
@@ -1749,7 +1749,7 @@ public static function getAllConfigData()
17491749
*
17501750
* @return string
17511751
*/
1752-
public function prepareConfigDataForDisplay($data)
1752+
public function prepareConfigDataForDisplay(array $data)
17531753
{
17541754
if (empty($data) === true) {
17551755
return '';
@@ -1786,7 +1786,7 @@ public function prepareConfigDataForDisplay($data)
17861786
*
17871787
* @return void
17881788
*/
1789-
public function printConfigData($data)
1789+
public function printConfigData(array $data)
17901790
{
17911791
echo $this->prepareConfigDataForDisplay($data);
17921792

src/Files/DummyFile.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DummyFile extends File
3030
*
3131
* @return void
3232
*/
33-
public function __construct($content, Ruleset $ruleset, Config $config)
33+
public function __construct(string $content, Ruleset $ruleset, Config $config)
3434
{
3535
$this->setContent($content);
3636

@@ -71,8 +71,14 @@ public function __construct($content, Ruleset $ruleset, Config $config)
7171
*
7272
* @return void
7373
*/
74-
public function setErrorCounts($errorCount, $warningCount, $fixableErrorCount, $fixableWarningCount, $fixedErrorCount, $fixedWarningCount)
75-
{
74+
public function setErrorCounts(
75+
int $errorCount,
76+
int $warningCount,
77+
int $fixableErrorCount,
78+
int $fixableWarningCount,
79+
int $fixedErrorCount,
80+
int $fixedWarningCount
81+
) {
7682
$this->errorCount = $errorCount;
7783
$this->warningCount = $warningCount;
7884
$this->fixableErrorCount = $fixableErrorCount;

0 commit comments

Comments
 (0)