Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrutinizer Auto-Fixes #1

Merged
merged 1 commit into from
May 19, 2016
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
14 changes: 7 additions & 7 deletions Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function run(InputArgs $inputArgs)
}

$arguments = $inputArgs->getArguments();
if(isset($arguments[0]) && $arguments[0] === 'self-init'){
if (isset($arguments[0]) && $arguments[0] === 'self-init') {
$directoryName = isset($arguments[1]) ? $arguments[1] : 'build';
$selfInit = new Commands\SelfInit();
$selfInit->setDistDirectory(__DIR__ . '/build-dist');
Expand All @@ -52,9 +52,9 @@ public function run(InputArgs $inputArgs)
if (is_file($bootstrapFile)) {
$this->log("Info: Found bootstrap.php in working directory.", 'dark_gray');
$container = require_once $bootstrapFile;
if($container === 1 || $container === TRUE){ // 1 = success, TRUE = already required
if ($container === 1 || $container === TRUE) { // 1 = success, TRUE = already required
$container = NULL;
}elseif(!($container instanceof Container)){
}elseif (!($container instanceof Container)) {
$this->log("Returned value from bootstrap.php must be instance of 'Genesis\\Container\\Container' or nothing (NULL).", 'red');
exit(255);
}
Expand Down Expand Up @@ -112,11 +112,11 @@ protected function createContainer($workingDir, $configFile, Container $bootstra
{
$factory = new ContainerFactory();
$factory->addConfig($workingDir . '/' . $configFile);
if(is_file($workingDir . '/config.local.neon')){
if (is_file($workingDir . '/config.local.neon')) {
$factory->addConfig($workingDir . '/config.local.neon');
}
$factory->setWorkingDirectory($workingDir);
if($bootstrapContainer !== NULL){
if ($bootstrapContainer !== NULL) {
$factory->addContainerToMerge($bootstrapContainer);
}
return $factory->create();
Expand Down Expand Up @@ -163,10 +163,10 @@ protected function getAutowiredProperties($class)
{
$return = [];
$reflectionClass = new \ReflectionClass($class);
foreach($reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $property){
foreach ($reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
$reflectionProp = new \ReflectionProperty($class, $property->getName());
$doc = $reflectionProp->getDocComment();
if(preg_match('#@inject ?([^\s]*)\s#s', $doc, $matches)){
if (preg_match('#@inject ?([^\s]*)\s#s', $doc, $matches)) {
$return[$property->getName()] = trim($matches[1]) !== '' ? $matches[1] : $property->getName();
}
}
Expand Down
6 changes: 3 additions & 3 deletions Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function runDefault()
{
$helpCommand = new Commands\Help;
foreach ($this->detectAvailableTasks() as $section => $tasks) {
if(!$helpCommand->hasSection($section)){
if (!$helpCommand->hasSection($section)) {
$helpCommand->addSection($section);
}
$helpCommand->setSectionTasks($section, $tasks);
Expand All @@ -51,11 +51,11 @@ protected function detectAvailableTasks()
if (preg_match('#^run(.*)#', $method->name, $match)) {
$doc = $method->getDocComment();
$section = NULL;
if(preg_match('#@section ?([^\s]*)\s#s', $doc, $m)){
if (preg_match('#@section ?([^\s]*)\s#s', $doc, $m)) {
$section = trim($m[1]);
}
$description = NULL;
if(preg_match('#([^@][a-zA-Z0-9]+)+#', $doc, $m)){
if (preg_match('#([^@][a-zA-Z0-9]+)+#', $doc, $m)) {
$description = trim($m[0]);
}
$tasks[$section][lcfirst($match[1])] = $description != '' ? $description : NULL;
Expand Down
4 changes: 2 additions & 2 deletions Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class Cli

public static function getColoredString($string, $foreground = NULL, $background = NULL)
{
if(!self::$enableColors){
if (!self::$enableColors) {
return $string;
}
if($foreground === NULL && $background === NULL){
if ($foreground === NULL && $background === NULL) {
return $string;
}

Expand Down
8 changes: 4 additions & 4 deletions commands/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ public function execute()
// detect max width
$minColumnWidth = 30;
foreach ($this->sections as $sectionName => $data) {
if(strlen($sectionName) > $minColumnWidth){
if (strlen($sectionName) > $minColumnWidth) {
$minColumnWidth = strlen($sectionName) + 5;
}
foreach ($data['tasks'] as $taskName => $description) {
if(strlen($taskName) > $minColumnWidth){
if (strlen($taskName) > $minColumnWidth) {
$minColumnWidth = strlen($taskName) + 2 + 5;
}
}
}
// empty section first
if(isset($this->sections[''])){
if (isset($this->sections[''])) {
$val = $this->sections[''];
unset($this->sections['']);
$this->sections = ['' => $val] + $this->sections;
Expand All @@ -85,7 +85,7 @@ public function execute()
echo "Available tasks:" . PHP_EOL;
foreach ($this->sections as $sectionName => $data) {
echo Cli::getColoredString($sectionName, 'yellow');
echo str_repeat(" ", $minColumnWidth - strlen($sectionName) + 2); // +2 = two spaces before taskName (below)
echo str_repeat(" ", $minColumnWidth - strlen($sectionName) + 2); // +2 = two spaces before taskName (below)
echo Cli::getColoredString($data['description'], 'dark_gray');
echo PHP_EOL;
foreach ($data['tasks'] as $taskName => $description) {
Expand Down
6 changes: 3 additions & 3 deletions commands/PhpUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function execute()

$cmd = escapeshellarg($this->options['executable']) . ' ';
if (isset($this->options['xdebugExtensionFile'])) {
if(!is_file($this->options['xdebugExtensionFile'])){ // PHP is quite when extension file does not exists
if (!is_file($this->options['xdebugExtensionFile'])) { // PHP is quite when extension file does not exists
$this->error("Xdebug extension file '{$this->options['xdebugExtensionFile']}' does not exists.");
}
$cmd .= '-d zend_extension=' . escapeshellarg($this->options['xdebugExtensionFile']) . ' ';
Expand All @@ -92,7 +92,7 @@ public function execute()

$currdir = getcwd();
$result = @chdir($this->workingDir);
if(!$result){
if (!$result) {
$this->error("Cannot change working directory to '$this->workingDir'.");
}

Expand All @@ -104,7 +104,7 @@ public function execute()
}

$result = @chdir($currdir);
if(!$result){
if (!$result) {
$this->error("Cannot change working directory back to '$currdir'.");
}
}
Expand Down
4 changes: 2 additions & 2 deletions commands/SelfInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function setDirname($dirname)
public function execute()
{
$buildDir = $this->workingDirectory . DIRECTORY_SEPARATOR . $this->dirname;
if(is_dir($buildDir)){
if (is_dir($buildDir)) {
$this->error("Directory '$this->dirname' in working directory '$this->workingDirectory' already exists.");
}
$directory = new Filesystem\Directory();
Expand All @@ -85,7 +85,7 @@ public function execute()
foreach ($directory->read($this->distDirectory) as $fileInfo) {
$newFile = $buildDir . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
$file->copy($fileInfo->getPathName(), $newFile);
if($fileInfo->getFilename() === 'build'){
if ($fileInfo->getFilename() === 'build') {
$file->makeExecutable($newFile);
}
}
Expand Down
6 changes: 3 additions & 3 deletions commands/filesystem/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public function clean($directory)
if ($file->isLink()) {
$this->checkPath($file->getPathName(), $directory);
$result = @unlink($file->getPathname());
if(!$result){
if (!$result) {
$this->error("Cannot delete symlink '$file'.");
}
} elseif ($file->isDir()) {
$this->checkPath($file->getPathName(), $directory);
$result = @rmdir($file->getPathName());
if(!$result){
if (!$result) {
$this->error("Cannot delete file '$file'.");
}
} elseif ($file->isFile()) {
$this->checkPath($file->getPathName(), $directory);
$result = @unlink($file->getPathname());
if(!$result){
if (!$result) {
$this->error("Cannot delete file '$file'.");
}
}
Expand Down
12 changes: 6 additions & 6 deletions commands/filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getSymlinksRelativeToCreate()
*/
public function addSymlinksRelativeToCreate(array $symlinksRelativeToCreate, $baseDir)
{
if(!isset($this->symlinksRelativeToCreate[$baseDir])){
if (!isset($this->symlinksRelativeToCreate[$baseDir])) {
$this->symlinksRelativeToCreate[$baseDir] = [];
}
$this->symlinksRelativeToCreate[$baseDir] = array_merge($this->symlinksRelativeToCreate[$baseDir], $symlinksRelativeToCreate);
Expand Down Expand Up @@ -110,7 +110,7 @@ public function addFilesToCopy(array $filesToCopy, $onDuplicate = 'error')

public function execute()
{
if(count($this->directoriesToCreate) > 0) {
if (count($this->directoriesToCreate) > 0) {
$this->log(Cli::getColoredString('Creating directories', 'light_blue'));
$command = new Directory();
foreach ($this->directoriesToCreate as $directory => $chmod) {
Expand All @@ -122,7 +122,7 @@ public function execute()
$this->log("Directory '$directory' created.");
}
}
if(count($this->directoriesToClean) > 0) {
if (count($this->directoriesToClean) > 0) {
$this->log(Cli::getColoredString('Cleaning directories', 'light_blue'));
$command = new Directory();
foreach ($this->directoriesToClean as $directory) {
Expand All @@ -148,11 +148,11 @@ public function execute()
$this->log("File '$options[source]' copied to '$destination'.");
}
}
if(count($this->symlinksRelativeToCreate) > 0) {
if (count($this->symlinksRelativeToCreate) > 0) {
$this->log(Cli::getColoredString('Creating symlinks', 'light_blue'));
$command = new \Genesis\Commands\Filesystem\Symlink();
foreach($this->symlinksRelativeToCreate as $baseDir => $symlinks){
foreach($symlinks as $link => $target) {
foreach ($this->symlinksRelativeToCreate as $baseDir => $symlinks) {
foreach ($symlinks as $link => $target) {
$absoluteLinkPath = $baseDir . '/' . $link;
if (is_link($absoluteLinkPath)) {
$this->log("Symlink '$link' already exists, skipping ...");
Expand Down
2 changes: 1 addition & 1 deletion commands/filesystem/Symlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function create($target, $link)
*/
public function createRelative($directory, $target, $link)
{
if(!is_dir($directory)){
if (!is_dir($directory)) {
$this->error("Directory '$directory' not found.");
}
$cmd = 'cd ' . escapeshellarg($directory) . ' && ln -s ' . escapeshellarg($target) . ' ' . escapeshellarg($link);
Expand Down
22 changes: 11 additions & 11 deletions config/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function create()
'workingDirectory' => $this->workingDirectory,
]
];
if($this->containersToMerge !== NULL){
if ($this->containersToMerge !== NULL) {
foreach ($this->containersToMerge as $containerToMerge) {
foreach ($containerToMerge->getParameters() as $k => $v) {
$config['parameters'][$k] = $v;
Expand Down Expand Up @@ -135,9 +135,9 @@ private function resolveFiles(array $files)
$return = [];
foreach ($files as $file) {
$array = $this->readFile($file);
if($array !== NULL){
if(isset($array['includes'])){
foreach($array['includes'] as $include){
if ($array !== NULL) {
if (isset($array['includes'])) {
foreach ($array['includes'] as $include) {
$return[] = dirname($file) . DIRECTORY_SEPARATOR . $include;
}
}
Expand All @@ -152,7 +152,7 @@ private function readConfigs($files, $config)
{
foreach ($files as $file) {
$array = $this->readFile($file);
if($array !== NULL) {
if ($array !== NULL) {
$config = array_replace_recursive($config, $array);
}
}
Expand Down Expand Up @@ -182,11 +182,11 @@ private function parseValues($config, & $allConfig = [], $keysPath = [])
foreach($value->attributes as $k => $v){
if(is_array($v)){
$value->attributes[$k] = $this->parseValues($v, $allConfig, array_merge($keysPath, [$key]));
}else{
} else{
$value->attributes[$k] = $this->parseValue($v, $allConfig);
}
}
}elseif (is_array($value)) {
} elseif (is_array($value)) {
$value = $this->parseValues($value, $allConfig, array_merge($keysPath, [$key]));
} elseif(!is_object($value)) {
$value = $this->parseValue($value, $allConfig);
Expand All @@ -198,11 +198,11 @@ private function parseValues($config, & $allConfig = [], $keysPath = [])
$config[$newKey] = $value;

// write to global config
$v =& $allConfig;
$v = & $allConfig;
foreach ($keysPath as $kp) {
$v =& $v[$kp];
$v = & $v[$kp];
}
if(!($value instanceof \Nette\Neon\Entity)) {
if (!($value instanceof \Nette\Neon\Entity)) {
$v[$newKey] = $value;
}
}
Expand Down Expand Up @@ -237,7 +237,7 @@ private function parseValue($value, $config)
private function resolveUnmergables($config)
{
foreach ($config as $key => $value) {
if(preg_match('#!$#', $key)){
if (preg_match('#!$#', $key)) {
$newKey = substr($key, 0, strlen($key) - 1);
$config[$newKey] = $value;
unset($config[$key]);
Expand Down