Skip to content

Commit e1e1ddd

Browse files
committed
Fix additional code issues with high warnings
1 parent 5c0f6ce commit e1e1ddd

13 files changed

+49
-57
lines changed

src/Command/ValidateCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
use Symfony\Component\Console\Input\InputOption;
1919
use Symfony\Component\Console\Output\OutputInterface;
2020

21-
2221
class ValidateCommand extends Command
2322
{
24-
2523
protected function configure(): void
2624
{
2725
$this
@@ -36,6 +34,11 @@ protected function configure(): void
3634
->addOption('debug', null, InputOption::VALUE_NONE, "Run in debug");
3735
}
3836

37+
/**
38+
* {@inheritDoc}
39+
*
40+
* @throws TestException
41+
*/
3942
protected function execute(InputInterface $input, OutputInterface $output): int
4043
{
4144
$dir = $input->getOption("dir");

src/Events/php_exporter.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function get_events()
7272
* @param string $name Name of the current event (used for error messages)
7373
* @param int $line Line where the current event is placed in
7474
*
75-
* @return null
75+
* @return void
7676
*/
7777
public function set_current_event($name, $line)
7878
{
@@ -85,7 +85,7 @@ public function set_current_event($name, $line)
8585
*
8686
* @param array $content Array with the lines of the file
8787
*
88-
* @return null
88+
* @return void
8989
*/
9090
public function set_content($content)
9191
{
@@ -109,10 +109,9 @@ public function crawl_php_file($file)
109109
if (strpos($content, "dispatcher->trigger_event('") || strpos($content, "dispatcher->dispatch('"))
110110
{
111111
$this->set_content(explode("\n", $content));
112-
for ($i = 0, $num_lines = count($this->file_lines); $i < $num_lines; $i++)
113-
{
112+
foreach ($this->file_lines as $i => $file_line) {
114113
$event_line = false;
115-
$found_trigger_event = strpos($this->file_lines[$i], "dispatcher->trigger_event('");
114+
$found_trigger_event = strpos($file_line, "dispatcher->trigger_event('");
116115
$arguments = array();
117116
if ($found_trigger_event !== false)
118117
{
@@ -129,7 +128,7 @@ public function crawl_php_file($file)
129128
}
130129
else
131130
{
132-
$found_dispatch = strpos($this->file_lines[$i], "dispatcher->dispatch('");
131+
$found_dispatch = strpos($file_line, "dispatcher->dispatch('");
133132
if ($found_dispatch !== false)
134133
{
135134
$event_line = $i;
@@ -288,10 +287,8 @@ public function get_vars_from_single_line_array($line, $throw_multiline = true)
288287

289288
return $vars_array;
290289
}
291-
else
292-
{
293-
throw new \LogicException("Can not find '\$vars = array();'-line for event '{$this->current_event}' in file '{$this->current_clean_file}:{$this->current_event_line}'. Are you using UNIX style linefeed?", 1);
294-
}
290+
291+
throw new \LogicException("Can not find '\$vars = array();'-line for event '{$this->current_event}' in file '{$this->current_clean_file}:{$this->current_event_line}'. Are you using UNIX style linefeed?", 1);
295292
}
296293

297294
/**
@@ -540,7 +537,7 @@ public function validate_event($event_name, $line)
540537
* @param array $vars_array Variables found in the array line
541538
* @param array $vars_docblock Variables found in the doc block
542539
*
543-
* @return null
540+
* @return void
544541
* @throws \LogicException
545542
*/
546543
public function validate_vars_docblock_array($vars_array, $vars_docblock)

src/Files/FileLoader.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function loadFile($fileName)
8080
else if ($size > 1)
8181
{
8282
// Try to load the file, the last part of $split contains the extension
83-
$file = self::tryLoadFile($fileName, $split[count($split) - 1]);
83+
$file = $this->tryLoadFile($fileName, $split[count($split) - 1]);
8484
}
8585
else // Blank filename?
8686
{
@@ -105,7 +105,7 @@ public function loadFile($fileName)
105105
* @param $fileName
106106
* @param $extension
107107
*
108-
* @return BinaryFile|ComposerFile|CssFile|HTMLFile|JavascriptFile|JsonFile|PHPFile|PlainFile|XmlFile|YmlFile|ImageFile|null
108+
* @return BinaryFile|ComposerFile|CssFile|HTMLFile|JavascriptFile|JsonFile|LangFile|LockFile|MigrationFile|PHPFile|PlainFile|XmlFile|YmlFile|ImageFile|null
109109
*/
110110
private function tryLoadFile($fileName, $extension)
111111
{
@@ -117,9 +117,7 @@ private function tryLoadFile($fileName, $extension)
117117
case 'php':
118118
// First, check if this file is a lang file.
119119
$file = basename($fileName);
120-
$dir = str_replace($file, '', $fileName);
121-
$dir = str_replace($this->basedir, '', $dir);
122-
$dir = str_replace('\\', '/', $dir);
120+
$dir = str_replace(array($file, $this->basedir, '\\'), array('', '', '/'), $fileName);
123121
$dir = explode('/', trim($dir, '/'));
124122
$dir = array_map('strtolower', $dir);
125123

@@ -140,21 +138,19 @@ private function tryLoadFile($fileName, $extension)
140138
return new HTMLFile($this->debug, $fileName, $this->rundir);
141139

142140
case 'json':
143-
if (strtolower(basename($fileName)) == 'composer.json')
141+
if (strtolower(basename($fileName)) === 'composer.json')
144142
{
145143
return new ComposerFile($this->debug, $fileName, $this->rundir);
146144
}
147-
else
148-
{
149-
return new JsonFile($this->debug, $fileName, $this->rundir);
150-
}
145+
146+
return new JsonFile($this->debug, $fileName, $this->rundir);
151147

152148
case 'yml':
153-
if (strtolower(basename($fileName)) == 'services.yml')
149+
if (strtolower(basename($fileName)) === 'services.yml')
154150
{
155151
return new ServiceFile($this->debug, $fileName, $this->rundir);
156152
}
157-
if (strtolower(basename($fileName)) == 'routing.yml')
153+
if (strtolower(basename($fileName)) === 'routing.yml')
158154
{
159155
return new RoutingFile($this->debug, $fileName, $this->rundir);
160156
}

src/Files/Type/YmlFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class YmlFile extends BaseFile implements YmlFileInterface
2020
{
2121
/** @var array */
22-
protected $yamlFile;
22+
protected mixed $yamlFile;
2323

2424
public function __construct($debug, $filename, $rundir)
2525
{
@@ -92,7 +92,7 @@ public function getYaml(): array
9292
* Get the file type for the specific file.
9393
* @return int
9494
*/
95-
function getFileType(): int
95+
public function getFileType(): int
9696
{
9797
return Type::TYPE_YML;
9898
}

src/Output/Message.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ public function __toString()
4444

4545
switch ($this->type)
4646
{
47-
case Output::NOTICE:
47+
case OutputInterface::NOTICE:
4848
return "<noticeb>Notice:</noticeb><notice> $this->message{$file}</notice>";
49-
case Output::WARNING:
49+
case OutputInterface::WARNING:
5050
return "<warningb>Warning:</warningb><warning> $this->message{$file}</warning>";
51-
case Output::ERROR:
51+
case OutputInterface::ERROR:
5252
return "<errorb>Error:</errorb><error> $this->message{$file}</error>";
53-
case Output::FATAL:
53+
case OutputInterface::FATAL:
5454
return "<fatalb>Fatal error:</fatalb><fatal> $this->message{$file}</fatal>";
55-
case Output::DEBUG:
55+
case OutputInterface::DEBUG:
5656
return $this->message;
5757
}
5858
}

src/Tests/BaseTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ public function validateFile(FileInterface $file)
9696
}
9797

9898
/**
99-
* @param array $dirList
99+
* @param array $dirListing
100100
*
101101
* @return mixed|void
102102
* @throws Exception\TestException
103103
*/
104-
public function validateDirectory(array $dirList)
104+
public function validateDirectory(array $dirListing)
105105
{
106106
throw new TestException("Test declared to be a directory listing test, but doesn't implement validateDirectory.");
107107
}
@@ -151,9 +151,7 @@ private function boolToLang($bool)
151151
*/
152152
public function __toString()
153153
{
154-
$string = 'Test: ' . $this->testName() . '. ';
155-
156-
return $string;
154+
return 'Test: ' . $this->testName() . '. ';
157155
}
158156

159157
/**
@@ -173,6 +171,6 @@ protected function isTest(?FileInterface $file = null)
173171
$dir = str_replace($this->basedir, '', $file->getFilename());
174172
$dir = explode("/", $dir);
175173

176-
return ($dir[0] == 'test' || $dir[0] == 'tests') && $dir[1] != 'testFiles';
174+
return ($dir[0] === 'test' || $dir[0] === 'tests') && $dir[1] !== 'testFiles';
177175
}
178176
}

src/Tests/TestStartup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ private function rrmdir($dir)
199199

200200
foreach ($objects as $object)
201201
{
202-
if ($object != "." && $object != "..")
202+
if ($object !== "." && $object !== "..")
203203
{
204-
if (filetype($dir . "/" . $object) == "dir")
204+
if (filetype($dir . "/" . $object) === "dir")
205205
{
206206
$this->rrmdir($dir . "/" . $object);
207207
}

src/Tests/Tests/epv_test_validate_directory_structure.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public function __construct($debug, OutputInterface $output, $basedir, $namespac
2929
$this->directory = true;
3030
}
3131

32-
public function validateDirectory(array $dirList, $validateLicenseContents = true)
32+
public function validateDirectory(array $dirListing, $validateLicenseContents = true)
3333
{
3434
$files = array(
3535
'license' => false,
3636
'composer' => false,
3737
);
38-
foreach ($dirList as $dir)
38+
foreach ($dirListing as $dir)
3939
{
4040
switch (strtolower(basename($dir)))
4141
{
@@ -72,11 +72,9 @@ public function validateDirectory(array $dirList, $validateLicenseContents = tru
7272
{
7373
$this->output->addMessage(Output::WARNING, 'The name of composer.json should be completely lowercase.');
7474
}
75-
$sp = str_replace('\\', '/', $dir);
76-
$sp = str_replace(str_replace('\\', '/', $this->opendir), '', $sp);
77-
$sp = str_replace('/composer.json', '', $sp);
75+
$sp = str_replace(array('\\', str_replace('\\', '/', $this->opendir), '/composer.json'), array('/', '', ''), $dir);
7876

79-
if (!empty($sp) && $sp[0] == '/')
77+
if (!empty($sp) && $sp[0] === '/')
8078
{
8179
// for some reason, there is a extra / on at least OS X
8280
$sp = substr($sp, 1, strlen($sp));

src/Tests/Tests/epv_test_validate_event_names.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public function __construct($debug, OutputInterface $output, $basedir, $namespac
2323
$this->directory = true;
2424
}
2525

26-
public function validateDirectory(array $dirList)
26+
public function validateDirectory(array $dirListing)
2727
{
2828
$exporter = new php_exporter($this->output, $this->opendir);
2929

30-
foreach ($dirList as $file)
30+
foreach ($dirListing as $file)
3131
{
3232
try
3333
{

src/Tests/Tests/epv_test_validate_languages.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ public function __construct($debug, OutputInterface $output, $basedir, $namespac
5656
}
5757

5858
/**
59-
* @param array $files
59+
* @param array $dirListing
6060
*
6161
* @return void
6262
*/
63-
public function validateDirectory(array $files)
63+
public function validateDirectory(array $dirListing)
6464
{
6565
$langs = [];
6666
$expected_keys = [];
6767
$expected_files = [];
6868

69-
foreach ($files as $file)
69+
foreach ($dirListing as $file)
7070
{
7171
if (preg_match('#^' . preg_quote($this->basedir, '/') . 'language[\/\\\\]([a-z_]+?)[\/\\\\](.+\.php)$#', $file, $matches) === 1)
7272
{

0 commit comments

Comments
 (0)