Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$finder = PhpCsFixer\Finder::create()
->ignoreDotFiles(false)
->ignoreVCS(true)
->exclude('vendor')
->exclude(['vendor', 'tests/Fixtures', 'test-files'])
->name('.changelog')
->in(__DIR__);

Expand Down Expand Up @@ -41,5 +41,8 @@
'sort_algorithm' => 'alpha',
'imports_order' => ['class', 'const', 'function'],
],
'trailing_comma_in_multiline' => [
'elements' => ['arrays'],
],
])
->setFinder($finder);
4 changes: 2 additions & 2 deletions bin/fix-cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cd "${PROJECT_DIRECTORY}";
PHP_CS_FIXER="${PROJECT_DIRECTORY}/vendor/bin/php-cs-fixer"
PHP_CS_CONFIG=".php-cs-fixer.php"

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

# shellcheck disable=SC2164
cd "${CURRENT_DIRECTORY}";
echo "[Done] Operation completed!"
echo "[Done] Operation completed!"
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@
}
},
"version": "0.14.4"
}
}
47 changes: 9 additions & 38 deletions src/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@

namespace AMWScan;

use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RuntimeException;

class Actions
{
/**
* Put contents.
*
* @param $filename
* @param $data
* @param int $flags
* @param null $context
*
Expand All @@ -39,9 +33,6 @@ public static function putContents($filename, $data, $flags = 0, $context = null
/**
* Clean Evil Code.
*
* @param $code
* @param $patternFound
*
* @return string|string[]|null
*/
public static function cleanEvilCode($code, $patternFound)
Expand All @@ -64,9 +55,6 @@ public static function cleanEvilCode($code, $patternFound)
/**
* Clean Evil Code Line.
*
* @param $code
* @param $patternFound
*
* @return string
*/
public static function cleanEvilCodeLine($code, $patternFound)
Expand All @@ -82,8 +70,6 @@ public static function cleanEvilCodeLine($code, $patternFound)
/**
* Delete File.
*
* @param $file
*
* @return bool
*/
public static function deleteFile($file)
Expand All @@ -98,16 +84,14 @@ public static function deleteFile($file)
/**
* Move to Quarantine.
*
* @param $file
*
* @return string
*/
public static function moveToQuarantine($file)
{
$quarantine = Scanner::getPathQuarantine() . DIRECTORY_SEPARATOR . str_replace(realpath(Scanner::getPathScan()), '', realpath($file));
$quarantine = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $quarantine);
if (!is_dir(dirname($quarantine)) && (!mkdir($concurrentDirectory = dirname($quarantine), 0755, true) && !is_dir($concurrentDirectory))) {
throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
}
rename($file, $quarantine);

Expand All @@ -117,8 +101,6 @@ public static function moveToQuarantine($file)
/**
* Move to Quarantine.
*
* @param $file
*
* @return string
*/
public static function makeBackup($file)
Expand All @@ -129,9 +111,9 @@ public static function makeBackup($file)
}
$backup = Scanner::getPathBackups() . DIRECTORY_SEPARATOR . str_replace($scanPath, '', realpath($file));
$backup = Path::get($backup);
if (!is_dir(dirname($backup)) &&
(!mkdir($concurrentDirectory = dirname($backup), 0755, true) && !is_dir($concurrentDirectory))) {
throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
if (!is_dir(dirname($backup))
&& (!mkdir($concurrentDirectory = dirname($backup), 0755, true) && !is_dir($concurrentDirectory))) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
}
copy($file, $backup);

Expand All @@ -141,9 +123,6 @@ public static function makeBackup($file)
/**
* Add to Whitelist.
*
* @param $file
* @param $patternFound
*
* @return false|int
*/
public static function addToWhitelist($file, $patternFound)
Expand Down Expand Up @@ -175,9 +154,6 @@ public static function addToWhitelist($file, $patternFound)

/**
* Open with VIM.
*
* @param $file
* @param $lineNumber
*/
public static function openWithVim($file, $lineNumber = null)
{
Expand All @@ -190,7 +166,7 @@ public static function openWithVim($file, $lineNumber = null)
['file', '/dev/tty', 'w'],
['file', '/dev/tty', 'w'],
];
$command = "vim ";
$command = 'vim ';
if ($lineNumber !== null && is_numeric($lineNumber) && $lineNumber > 0) {
$command .= "+$lineNumber ";
}
Expand All @@ -206,9 +182,6 @@ public static function openWithVim($file, $lineNumber = null)

/**
* Open with Nano.
*
* @param $file
* @param $lineNumber
*/
public static function openWithNano($file, $lineNumber = null)
{
Expand All @@ -221,7 +194,7 @@ public static function openWithNano($file, $lineNumber = null)
['file', '/dev/tty', 'w'],
['file', '/dev/tty', 'w'],
];
$command = "nano ";
$command = 'nano ';
if ($lineNumber !== null && is_numeric($lineNumber) && $lineNumber > 0) {
$command .= "+$lineNumber ";
}
Expand All @@ -248,16 +221,14 @@ public static function cleanQuarantine()
/**
* Unlink.
*
* @param $path
*
* @return bool
*/
protected static function unlink($path)
{
if (is_dir($path) && !is_link($path)) {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);

foreach ($files as $fileinfo) {
Expand Down
9 changes: 2 additions & 7 deletions src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace AMWScan;

use AMWScan\Abstracts\SingletonAbstract;
use RuntimeException;

class Cache extends SingletonAbstract
{
Expand Down Expand Up @@ -43,11 +42,11 @@ class Cache extends SingletonAbstract
protected function __construct()
{
parent::__construct();
$userIdentifier = function_exists('posix_getuid') ? (string) posix_getuid() : md5(get_current_user());
$userIdentifier = function_exists('posix_getuid') ? (string)posix_getuid() : md5(get_current_user());
$tempdir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . Scanner::getLowerName() . DIRECTORY_SEPARATOR . $userIdentifier . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;

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

$this->tempdir = $tempdir;
Expand All @@ -57,7 +56,6 @@ protected function __construct()
* Set cache item.
*
* @param string $key
* @param mixed $value
* @param int $ttl
*
* @return bool
Expand Down Expand Up @@ -109,9 +107,6 @@ public function touch($key, $ttl = 3600)
* Get cache item.
*
* @param string $key
* @param mixed $default
*
* @return mixed
*/
public function get($key, $default = null)
{
Expand Down
17 changes: 2 additions & 15 deletions src/CodeMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@

class CodeMatch
{
const DANGEROUS = 'danger';
const WARNING = 'warn';
public const DANGEROUS = 'danger';
public const WARNING = 'warn';

/**
* Get PHP code parts contained on the text.
*
* @param $content
*
* @return array
*/
public static function getCode($content)
Expand All @@ -33,9 +31,6 @@ public static function getCode($content)
/**
* Get match line number.
*
* @param $lastMatch
* @param $contentRaw
*
* @return int|null
*/
public static function getLineNumber($lastMatch, $contentRaw)
Expand All @@ -55,10 +50,6 @@ public static function getLineNumber($lastMatch, $contentRaw)
/**
* Get console pattern found match output text.
*
* @param $type
* @param $name
* @param $description
* @param $match
* @param null $line
*
* @return string
Expand All @@ -81,8 +72,6 @@ public static function getText($type, $name, $description, $match, $line = null)
/**
* Generate regex for function pattern.
*
* @param $func
*
* @return string
*/
public static function patternFunction($func)
Expand All @@ -93,8 +82,6 @@ public static function patternFunction($func)
/**
* Clean function match result.
*
* @param $match
*
* @return string|null
*/
public static function cleanFunctionResult($match)
Expand Down
8 changes: 1 addition & 7 deletions src/Console/Argument.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Antimalware Scanner.
*
Expand Down Expand Up @@ -27,19 +28,12 @@ class Argument
* @var bool
*/
public $required = false;
/**
* @var mixed
*/
public $defaultValue;
/**
* @var mixed
*/
public $help;

/**
* Argument constructor.
*
* @param $name
* @param array $options
*/
public function __construct($name, $options = [])
Expand Down
11 changes: 1 addition & 10 deletions src/Console/Flag.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Antimalware Scanner.
*
Expand Down Expand Up @@ -35,23 +36,13 @@ class Flag
* @var string
*/
public $valueName;
/**
* @var mixed
*/
public $defaultValue;
/**
* @var mixed
*/
public $var;
/**
* @var mixed
*/
public $help;

/**
* Flag constructor.
*
* @param $name
* @param array $options
* @param null $callback
*/
Expand Down
Loading
Loading