Skip to content

Commit cd70b7a

Browse files
Merge pull request #146 from helmo/phpcs3
Fix a false positive and Phpcs cleanup
2 parents aeb2f68 + 7b312a2 commit cd70b7a

21 files changed

Lines changed: 75 additions & 213 deletions

.php-cs-fixer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$finder = PhpCsFixer\Finder::create()
44
->ignoreDotFiles(false)
55
->ignoreVCS(true)
6-
->exclude('vendor')
6+
->exclude(['vendor', 'tests/Fixtures', 'test-files'])
77
->name('.changelog')
88
->in(__DIR__);
99

@@ -41,5 +41,8 @@
4141
'sort_algorithm' => 'alpha',
4242
'imports_order' => ['class', 'const', 'function'],
4343
],
44+
'trailing_comma_in_multiline' => [
45+
'elements' => ['arrays'],
46+
],
4447
])
4548
->setFinder($finder);

bin/fix-cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cd "${PROJECT_DIRECTORY}";
1313
PHP_CS_FIXER="${PROJECT_DIRECTORY}/vendor/bin/php-cs-fixer"
1414
PHP_CS_CONFIG=".php-cs-fixer.php"
1515

16-
git diff --cached --name-only --diff-filter=ACMR HEAD -- '*.php' | while read line; do
16+
git diff --cached --name-only --diff-filter=ACMR HEAD -- '*.php'| grep -v -e 'tests/Fixtures/' -e 'test-files/' | while read line; do
1717
echo " - Fixing: ${line}"
1818
# PHP CS Fixer
1919
PHP_CS_FIXER_IGNORE_ENV=1 php "${CURRENT_DIRECTORY}/run" ${PHP_CS_FIXER} fix --config=${PHP_CS_CONFIG} --verbose ${line};
@@ -22,4 +22,4 @@ done
2222

2323
# shellcheck disable=SC2164
2424
cd "${CURRENT_DIRECTORY}";
25-
echo "[Done] Operation completed!"
25+
echo "[Done] Operation completed!"

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@
111111
}
112112
},
113113
"version": "0.14.4"
114-
}
114+
}

src/Actions.php

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,11 @@
1111

1212
namespace AMWScan;
1313

14-
use RecursiveDirectoryIterator;
15-
use RecursiveIteratorIterator;
16-
use RuntimeException;
17-
1814
class Actions
1915
{
2016
/**
2117
* Put contents.
2218
*
23-
* @param $filename
24-
* @param $data
2519
* @param int $flags
2620
* @param null $context
2721
*
@@ -39,9 +33,6 @@ public static function putContents($filename, $data, $flags = 0, $context = null
3933
/**
4034
* Clean Evil Code.
4135
*
42-
* @param $code
43-
* @param $patternFound
44-
*
4536
* @return string|string[]|null
4637
*/
4738
public static function cleanEvilCode($code, $patternFound)
@@ -64,9 +55,6 @@ public static function cleanEvilCode($code, $patternFound)
6455
/**
6556
* Clean Evil Code Line.
6657
*
67-
* @param $code
68-
* @param $patternFound
69-
*
7058
* @return string
7159
*/
7260
public static function cleanEvilCodeLine($code, $patternFound)
@@ -82,8 +70,6 @@ public static function cleanEvilCodeLine($code, $patternFound)
8270
/**
8371
* Delete File.
8472
*
85-
* @param $file
86-
*
8773
* @return bool
8874
*/
8975
public static function deleteFile($file)
@@ -98,16 +84,14 @@ public static function deleteFile($file)
9884
/**
9985
* Move to Quarantine.
10086
*
101-
* @param $file
102-
*
10387
* @return string
10488
*/
10589
public static function moveToQuarantine($file)
10690
{
10791
$quarantine = Scanner::getPathQuarantine() . DIRECTORY_SEPARATOR . str_replace(realpath(Scanner::getPathScan()), '', realpath($file));
10892
$quarantine = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $quarantine);
10993
if (!is_dir(dirname($quarantine)) && (!mkdir($concurrentDirectory = dirname($quarantine), 0755, true) && !is_dir($concurrentDirectory))) {
110-
throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
94+
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
11195
}
11296
rename($file, $quarantine);
11397

@@ -117,8 +101,6 @@ public static function moveToQuarantine($file)
117101
/**
118102
* Move to Quarantine.
119103
*
120-
* @param $file
121-
*
122104
* @return string
123105
*/
124106
public static function makeBackup($file)
@@ -129,9 +111,9 @@ public static function makeBackup($file)
129111
}
130112
$backup = Scanner::getPathBackups() . DIRECTORY_SEPARATOR . str_replace($scanPath, '', realpath($file));
131113
$backup = Path::get($backup);
132-
if (!is_dir(dirname($backup)) &&
133-
(!mkdir($concurrentDirectory = dirname($backup), 0755, true) && !is_dir($concurrentDirectory))) {
134-
throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
114+
if (!is_dir(dirname($backup))
115+
&& (!mkdir($concurrentDirectory = dirname($backup), 0755, true) && !is_dir($concurrentDirectory))) {
116+
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
135117
}
136118
copy($file, $backup);
137119

@@ -141,9 +123,6 @@ public static function makeBackup($file)
141123
/**
142124
* Add to Whitelist.
143125
*
144-
* @param $file
145-
* @param $patternFound
146-
*
147126
* @return false|int
148127
*/
149128
public static function addToWhitelist($file, $patternFound)
@@ -175,9 +154,6 @@ public static function addToWhitelist($file, $patternFound)
175154

176155
/**
177156
* Open with VIM.
178-
*
179-
* @param $file
180-
* @param $lineNumber
181157
*/
182158
public static function openWithVim($file, $lineNumber = null)
183159
{
@@ -190,7 +166,7 @@ public static function openWithVim($file, $lineNumber = null)
190166
['file', '/dev/tty', 'w'],
191167
['file', '/dev/tty', 'w'],
192168
];
193-
$command = "vim ";
169+
$command = 'vim ';
194170
if ($lineNumber !== null && is_numeric($lineNumber) && $lineNumber > 0) {
195171
$command .= "+$lineNumber ";
196172
}
@@ -206,9 +182,6 @@ public static function openWithVim($file, $lineNumber = null)
206182

207183
/**
208184
* Open with Nano.
209-
*
210-
* @param $file
211-
* @param $lineNumber
212185
*/
213186
public static function openWithNano($file, $lineNumber = null)
214187
{
@@ -221,7 +194,7 @@ public static function openWithNano($file, $lineNumber = null)
221194
['file', '/dev/tty', 'w'],
222195
['file', '/dev/tty', 'w'],
223196
];
224-
$command = "nano ";
197+
$command = 'nano ';
225198
if ($lineNumber !== null && is_numeric($lineNumber) && $lineNumber > 0) {
226199
$command .= "+$lineNumber ";
227200
}
@@ -248,16 +221,14 @@ public static function cleanQuarantine()
248221
/**
249222
* Unlink.
250223
*
251-
* @param $path
252-
*
253224
* @return bool
254225
*/
255226
protected static function unlink($path)
256227
{
257228
if (is_dir($path) && !is_link($path)) {
258-
$files = new RecursiveIteratorIterator(
259-
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
260-
RecursiveIteratorIterator::CHILD_FIRST
229+
$files = new \RecursiveIteratorIterator(
230+
new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS),
231+
\RecursiveIteratorIterator::CHILD_FIRST
261232
);
262233

263234
foreach ($files as $fileinfo) {

src/Cache.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace AMWScan;
1313

1414
use AMWScan\Abstracts\SingletonAbstract;
15-
use RuntimeException;
1615

1716
class Cache extends SingletonAbstract
1817
{
@@ -43,11 +42,11 @@ class Cache extends SingletonAbstract
4342
protected function __construct()
4443
{
4544
parent::__construct();
46-
$userIdentifier = function_exists('posix_getuid') ? (string) posix_getuid() : md5(get_current_user());
45+
$userIdentifier = function_exists('posix_getuid') ? (string)posix_getuid() : md5(get_current_user());
4746
$tempdir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . Scanner::getLowerName() . DIRECTORY_SEPARATOR . $userIdentifier . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
4847

4948
if (!is_dir($tempdir) && (!mkdir($tempdir, 0700, true) && !is_dir($tempdir))) {
50-
throw new RuntimeException(sprintf('Temp Directory "%s" was not created', $tempdir));
49+
throw new \RuntimeException(sprintf('Temp Directory "%s" was not created', $tempdir));
5150
}
5251

5352
$this->tempdir = $tempdir;
@@ -57,7 +56,6 @@ protected function __construct()
5756
* Set cache item.
5857
*
5958
* @param string $key
60-
* @param mixed $value
6159
* @param int $ttl
6260
*
6361
* @return bool
@@ -109,9 +107,6 @@ public function touch($key, $ttl = 3600)
109107
* Get cache item.
110108
*
111109
* @param string $key
112-
* @param mixed $default
113-
*
114-
* @return mixed
115110
*/
116111
public function get($key, $default = null)
117112
{

src/CodeMatch.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313

1414
class CodeMatch
1515
{
16-
const DANGEROUS = 'danger';
17-
const WARNING = 'warn';
16+
public const DANGEROUS = 'danger';
17+
public const WARNING = 'warn';
1818

1919
/**
2020
* Get PHP code parts contained on the text.
2121
*
22-
* @param $content
23-
*
2422
* @return array
2523
*/
2624
public static function getCode($content)
@@ -33,9 +31,6 @@ public static function getCode($content)
3331
/**
3432
* Get match line number.
3533
*
36-
* @param $lastMatch
37-
* @param $contentRaw
38-
*
3934
* @return int|null
4035
*/
4136
public static function getLineNumber($lastMatch, $contentRaw)
@@ -55,10 +50,6 @@ public static function getLineNumber($lastMatch, $contentRaw)
5550
/**
5651
* Get console pattern found match output text.
5752
*
58-
* @param $type
59-
* @param $name
60-
* @param $description
61-
* @param $match
6253
* @param null $line
6354
*
6455
* @return string
@@ -81,8 +72,6 @@ public static function getText($type, $name, $description, $match, $line = null)
8172
/**
8273
* Generate regex for function pattern.
8374
*
84-
* @param $func
85-
*
8675
* @return string
8776
*/
8877
public static function patternFunction($func)
@@ -93,8 +82,6 @@ public static function patternFunction($func)
9382
/**
9483
* Clean function match result.
9584
*
96-
* @param $match
97-
*
9885
* @return string|null
9986
*/
10087
public static function cleanFunctionResult($match)

src/Console/Argument.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* PHP Antimalware Scanner.
45
*
@@ -27,19 +28,12 @@ class Argument
2728
* @var bool
2829
*/
2930
public $required = false;
30-
/**
31-
* @var mixed
32-
*/
3331
public $defaultValue;
34-
/**
35-
* @var mixed
36-
*/
3732
public $help;
3833

3934
/**
4035
* Argument constructor.
4136
*
42-
* @param $name
4337
* @param array $options
4438
*/
4539
public function __construct($name, $options = [])

src/Console/Flag.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* PHP Antimalware Scanner.
45
*
@@ -35,23 +36,13 @@ class Flag
3536
* @var string
3637
*/
3738
public $valueName;
38-
/**
39-
* @var mixed
40-
*/
4139
public $defaultValue;
42-
/**
43-
* @var mixed
44-
*/
4540
public $var;
46-
/**
47-
* @var mixed
48-
*/
4941
public $help;
5042

5143
/**
5244
* Flag constructor.
5345
*
54-
* @param $name
5546
* @param array $options
5647
* @param null $callback
5748
*/

0 commit comments

Comments
 (0)