PHPStorm refactoring.

This commit is contained in:
Andrés Montañez 2014-08-06 14:01:39 -03:00
parent 4c584b2634
commit fddeebe59a
48 changed files with 2011 additions and 1996 deletions

View file

@ -30,8 +30,7 @@ class Autoload
//Try to load a normal Mage class (or Task). Think that Mage component is compiled to .phar
$baseDir = dirname(dirname(__FILE__));
$classFileWithinPhar = $baseDir . $postfix;
if($this->isReadable($classFileWithinPhar))
{
if ($this->isReadable($classFileWithinPhar)) {
/** @noinspection PhpIncludeInspection */
require_once $classFileWithinPhar;
return true;
@ -39,7 +38,7 @@ class Autoload
//Try to load a custom Task or Class. Notice that the path is absolute to CWD
$classFileOutsidePhar = getcwd() . '/.mage/tasks' . $postfix;
if($this->isReadable($classFileOutsidePhar)){
if ($this->isReadable($classFileOutsidePhar)) {
/** @noinspection PhpIncludeInspection */
require_once $classFileOutsidePhar;
return true;

View file

@ -24,7 +24,7 @@ class CompileCommand extends AbstractCommand
/**
* @see \Mage\Compile::compile()
*/
public function run ()
public function run()
{
if (ini_get('phar.readonly')) {
Console::output('The <purple>php.ini</purple> variable <light_red>phar.readonly</light_red> must be <yellow>Off</yellow>.', 1, 2);

View file

@ -55,7 +55,8 @@ class InstallCommand extends AbstractCommand
// Check if there is already a symlink
if (file_exists($destinationDir . '/' . 'latest')
&& is_link($destinationDir . '/' . 'latest')) {
&& is_link($destinationDir . '/' . 'latest')
) {
unlink($destinationDir . '/' . 'latest');
}

View file

@ -26,7 +26,7 @@ class VersionCommand extends AbstractCommand
*/
public function run()
{
Console::output('Running <blue>Magallanes</blue> version <dark_gray>' . MAGALLANES_VERSION .'</dark_gray>', 0, 2);
Console::output('Running <blue>Magallanes</blue> version <dark_gray>' . MAGALLANES_VERSION . '</dark_gray>', 0, 2);
}
}

View file

@ -40,7 +40,7 @@ class Factory
$className = 'Mage\\Command\\BuiltIn\\' . $commandName . 'Command';
/** @var AbstractCommand $instance */
$instance = new $className;
if(!is_a($instance, "Mage\Command\AbstractCommand")) {
if (!is_a($instance, "Mage\Command\AbstractCommand")) {
throw new Exception('The command ' . $commandName . ' must be an instance of Mage\Command\AbstractCommand.');
}

View file

@ -42,11 +42,11 @@ class Compiler
/** @var \SplFileInfo $path */
foreach ($iterator as $path) {
if ($path->isFile()) {
$phar->addFromString(str_replace(dirname(__DIR__).'/', '', $path->getPathname()), file_get_contents($path));
$phar->addFromString(str_replace(dirname(__DIR__) . '/', '', $path->getPathname()), file_get_contents($path));
}
}
$binary = file(__DIR__.'/../bin/mage');
$binary = file(__DIR__ . '/../bin/mage');
unset($binary[0]);
$binary = implode(PHP_EOL, $binary);

View file

@ -116,7 +116,8 @@ class Config
* @return array
* @throws Config\ConfigNotFoundException
*/
protected function loadGeneral($filePath){
protected function loadGeneral($filePath)
{
return $this->parseConfigFile($filePath);
}
@ -142,6 +143,7 @@ class Config
return $settings;
}
/**
* Loads the Environment configuration
* @param $filePath string
@ -171,14 +173,13 @@ class Config
{
$environment = $this->getEnvironment();
if(!empty($environment))
{
if (!empty($environment)) {
$configFilePath = getcwd() . '/.mage/config/environment/' . $environment . '.yml';
try {
$this->environmentConfig = $this->loadEnvironment($configFilePath);
} catch (ConfigNotFoundException $e) {
throw new RequiredConfigNotFoundException("Not found required config $configFilePath for environment $environment", 0 , $e);
throw new RequiredConfigNotFoundException("Not found required config $configFilePath for environment $environment", 0, $e);
}
}
@ -191,18 +192,17 @@ class Config
*/
protected function isRunInSpecialMode(array $parameters)
{
if(empty($parameters))
if (empty($parameters))
return true;
foreach($parameters as $parameter)
{
if(isset(Console::$paramsNotRequiringEnvironment[$parameter]))
{
foreach ($parameters as $parameter) {
if (isset(Console::$paramsNotRequiringEnvironment[$parameter])) {
return true;
}
}
return false;
}
/**
* Load the Configuration and parses the Arguments
*
@ -324,7 +324,7 @@ class Config
}
if (isset($config[$configStage])) {
$tasksData = ($config[$configStage] ? (array) $config[$configStage] : array());
$tasksData = ($config[$configStage] ? (array)$config[$configStage] : array());
foreach ($tasksData as $taskData) {
if (is_array($taskData)) {
$tasks[] = array(
@ -352,7 +352,7 @@ class Config
$envConfig = $this->getEnvironmentConfig();
if (isset($envConfig['hosts'])) {
if (is_array($envConfig['hosts'])) {
$hosts = (array) $envConfig['hosts'];
$hosts = (array)$envConfig['hosts'];
} else if (is_string($envConfig['hosts']) && file_exists($envConfig['hosts']) && is_readable($envConfig['hosts'])) {
$hosts = $this->getHostsFromFile($envConfig['hosts']);
}
@ -575,13 +575,13 @@ class Config
*/
public function parseConfigFile($filePath)
{
if(!file_exists($filePath))
{
if (!file_exists($filePath)) {
throw new ConfigNotFoundException("Cannot find the file at path $filePath");
}
return $this->parseConfigText(file_get_contents($filePath));
}
public function parseConfigText($input)
{
return Yaml::parse($input);

View file

@ -28,7 +28,7 @@ class Console
* TODO refactor into own static class
* @var array
*/
public static $paramsNotRequiringEnvironment = array('install'=>'install', 'upgrade'=>'upgrade', 'version'=>'version');
public static $paramsNotRequiringEnvironment = array('install' => 'install', 'upgrade' => 'upgrade', 'version' => 'version');
/**
* Handler to the current Log File.
@ -75,7 +75,7 @@ class Console
$exitCode = 10;
// Declare a Shutdown Closure
register_shutdown_function(function() {
register_shutdown_function(function () {
// Only Unlock if there was an error
if (error_get_last() !== null) {
if (file_exists(getcwd() . '/.mage/~working.lock')) {
@ -247,7 +247,7 @@ class Console
*/
public static function readInput()
{
$fp = fopen("php://stdin","r");
$fp = fopen("php://stdin", "r");
$line = '';
$line = fgets($fp);

View file

@ -66,8 +66,7 @@ class Mailer
array('{project}', '{environment}', '{result}'),
array($this->project, $this->environment, $result ? 'SUCCESS' : 'FAILURE'),
self::SUBJECT
)
;
);
$attachment = chunk_split(base64_encode(file_get_contents($this->logFile)));
$message = 'This is a multi-part message in MIME format.' . self::EOL
@ -83,8 +82,7 @@ class Mailer
. 'Content-Disposition: attachment' . self::EOL
. self::EOL
. $attachment . self::EOL
. '--Mage-mixed-' . $boundary . '--' . self::EOL
;
. '--Mage-mixed-' . $boundary . '--' . self::EOL;
@mail($this->address, $subject, $message, $headers);
}

View file

@ -197,14 +197,14 @@ abstract class AbstractTask
}
// if general.yml includes "ssy_needs_tty: true", then add "-t" to the ssh command
$needs_tty = ($this->getConfig()->general('ssh_needs_tty',false) ? '-t' : '');
$needs_tty = ($this->getConfig()->general('ssh_needs_tty', false) ? '-t' : '');
$localCommand = 'ssh ' . $this->getConfig()->getHostIdentityFileOption() . $needs_tty . ' -p ' . $this->getConfig()->getHostPort() . ' '
. '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '
. $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName();
$remoteCommand = str_replace('"', '\"', $command);
if($cdToDirectoryFirst){
if ($cdToDirectoryFirst) {
$remoteCommand = 'cd ' . rtrim($this->getConfig()->deployment('to'), '/') . $releasesDirectory . ' && ' . $remoteCommand;
}
$localCommand .= ' ' . '"sh -c \"' . $remoteCommand . '\""';
@ -299,7 +299,7 @@ abstract class AbstractTask
$commands = array();
$commands[] = 'tar xfz ' . $currentRelease;
$commands[] = 'rm -rf ' . $currentReleaseDirectory;
$commands[] = 'mv ' .$currentReleaseDirectoryTemp . ' ' . $currentReleaseDirectory;
$commands[] = 'mv ' . $currentReleaseDirectoryTemp . ' ' . $currentReleaseDirectory;
$command = implode(' && ', $commands);
$result = $this->runCommandRemote($command, $output);
return $result;

View file

@ -58,7 +58,7 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
//Check if target user:group is specified
$userGroup = $this->getConfig()->deployment('owner');
// Fetch the user and group from base directory; defaults usergroup to 33:33
if(empty($userGroup)){
if (empty($userGroup)) {
$user = '33';
$group = '33';
$directoryInfos = '';
@ -66,14 +66,14 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
// "stat" command don't behave the same on different systems, ls output format also varies
// and awk parameters need special care depending on the executing shell
$resultFetch = $this->runCommandRemote("ls -ld .", $directoryInfos);
if(!empty($directoryInfos)){
if (!empty($directoryInfos)) {
//uniformize format as it depends on the system deployed on
$directoryInfos = trim(str_replace(array(" ", "\t"), ' ', $directoryInfos));
$infoArray = explode(' ', $directoryInfos);
if(!empty($infoArray[2])) {
if (!empty($infoArray[2])) {
$user = $infoArray[2];
}
if(!empty($infoArray[3])) {
if (!empty($infoArray[3])) {
$group = $infoArray[3];
}
$userGroup = $user . ':' . $group;

View file

@ -32,7 +32,7 @@ abstract class BaseStrategyTaskAbstract extends AbstractTask implements IsReleas
if ($overrideRelease == true) {
$releaseToOverride = false;
$resultFetch = $this->runCommandRemote('ls -ld '.$symlink.' | cut -d"/" -f2', $releaseToOverride);
$resultFetch = $this->runCommandRemote('ls -ld ' . $symlink . ' | cut -d"/" -f2', $releaseToOverride);
if ($resultFetch && is_numeric($releaseToOverride)) {
$this->getConfig()->setReleaseId($releaseToOverride);
}

View file

@ -78,11 +78,11 @@ class GitRebaseTask extends BaseStrategyTaskAbstract implements IsReleaseAware
$result = $this->runCommandRemote($command) && $result;
// Stash if Working Copy is not clean
if(!$status) {
if (!$status) {
$stashResult = '';
$command = $this->getReleasesAwareCommand('git stash');
$result = $this->runCommandRemote($command, $stashResult) && $result;
if($stashResult != "No local changes to save") {
if ($stashResult != "No local changes to save") {
$stashed = true;
}
}

View file

@ -32,7 +32,7 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
return 'Deploy via Rsync (with Releases override) [built-in]';
} else {
$rsync_copy = $this->getConfig()->deployment("rsync");
if ( $rsync_copy && is_array($rsync_copy) && $rsync_copy['copy'] ) {
if ($rsync_copy && is_array($rsync_copy) && $rsync_copy['copy']) {
return 'Deploy via Rsync (with Releases) [built-in, incremental]';
} else {
return 'Deploy via Rsync (with Releases) [built-in]';
@ -72,10 +72,10 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
// rsync: { copy: yes }
$rsync_copy = $this->getConfig()->deployment('rsync');
// If copy_tool_rsync, use rsync rather than cp for finer control of what is copied
if ( $rsync_copy && is_array($rsync_copy) && $rsync_copy['copy'] && isset($rsync_copy['copy_tool_rsync']) ) {
if ($rsync_copy && is_array($rsync_copy) && $rsync_copy['copy'] && isset($rsync_copy['copy_tool_rsync'])) {
$this->runCommandRemote("rsync -a {$this->excludes(array_merge($excludes, $rsync_copy['rsync_excludes']))} "
. "$releasesDirectory/$currentRelease/ $releasesDirectory/{$this->getConfig()->getReleaseId()}");
} elseif ( $rsync_copy && is_array($rsync_copy) && $rsync_copy['copy'] ) {
} elseif ($rsync_copy && is_array($rsync_copy) && $rsync_copy['copy']) {
$this->runCommandRemote('cp -R ' . $releasesDirectory . '/' . $currentRelease . ' ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
} else {
$this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());

View file

@ -56,7 +56,7 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
. '/' . $releasesDirectory
. '/' . $this->getConfig()->getReleaseId();
$output = null;
$this->runCommandRemote('mkdir -p ' . $deployToDirectory, $output , false);
$this->runCommandRemote('mkdir -p ' . $deployToDirectory, $output, false);
}
// Create Tar Gz

View file

@ -56,7 +56,7 @@ class EncryptTask extends AbstractTask
*
* @var array
*/
private $default = array ();
private $default = array();
/**
* Array of YAML Ioncube
@ -64,7 +64,7 @@ class EncryptTask extends AbstractTask
*
* @var array
*/
private $yaml = array ();
private $yaml = array();
/**
* Array of file Ioncube
@ -73,7 +73,7 @@ class EncryptTask extends AbstractTask
*
* @var array
*/
private $file = array ();
private $file = array();
/**
* Source directory as used by
@ -106,7 +106,7 @@ class EncryptTask extends AbstractTask
*
* @var array
*/
private $mageConfig = array ();
private $mageConfig = array();
/**
* Final version of the IonCube
@ -115,7 +115,7 @@ class EncryptTask extends AbstractTask
*
* @var array
*/
private $ionCubeConfig = array ();
private $ionCubeConfig = array();
/**
* Default encoder version to use
@ -171,7 +171,8 @@ class EncryptTask extends AbstractTask
*
* @see \Mage\Task\AbstractTask::getName()
*/
public function getName() {
public function getName()
{
return $this->name;
}
@ -180,9 +181,10 @@ class EncryptTask extends AbstractTask
*
* @see \Mage\Task\AbstractTask::init()
*/
public function init() {
public function init()
{
// Set the default extensions to ignore
$this->checkIgnoreExtens = array (
$this->checkIgnoreExtens = array(
'jpg',
'jpeg',
'png',
@ -196,7 +198,7 @@ class EncryptTask extends AbstractTask
);
// Get any options specfic to this task
$this->mageConfig = $this->getConfig()->environmentConfig( 'ioncube' );
$this->mageConfig = $this->getConfig()->environmentConfig('ioncube');
/*
* Get all our IonCube config options
*/
@ -204,12 +206,12 @@ class EncryptTask extends AbstractTask
/*
* get the source code location
*/
$this->source = $this->getConfig ()->deployment ( 'from' );
$this->source = $this->getConfig()->deployment('from');
/*
* remove trailing slash if present
*/
if (substr ( $this->source, - 1 ) == DIRECTORY_SEPARATOR) {
$this->source = substr ( $this->source, 0, - 1 );
if (substr($this->source, -1) == DIRECTORY_SEPARATOR) {
$this->source = substr($this->source, 0, -1);
}
/*
* Set the name of the folder that the un-encrypted
@ -224,7 +226,7 @@ class EncryptTask extends AbstractTask
* Check if we have been given an encoder script
* If not then we will just use the default
*/
if (isset ( $this->mageConfig ['encoder'] )) {
if (isset ($this->mageConfig ['encoder'])) {
$this->encoder = $this->mageConfig ['encoder'];
}
/*
@ -232,15 +234,15 @@ class EncryptTask extends AbstractTask
* supplied, this defines how the 3 differant
* config files will be merged together.
*/
if (isset ( $this->mageConfig ['override'] )) {
if (isset ($this->mageConfig ['override'])) {
$this->ionOverRide = $this->mageConfig ['override'];
}
/*
* Check if we have been asked to
* confirm all encodings
*/
if (isset ( $this->mageConfig ['checkencoding'])) {
$this->checkEncoding=true;
if (isset ($this->mageConfig ['checkencoding'])) {
$this->checkEncoding = true;
}
/*
* Check if we have been passed any extra
@ -248,8 +250,8 @@ class EncryptTask extends AbstractTask
* encrypt/encode file check
*
*/
if (isset ( $this->mageConfig ['checkignoreextens'])) {
$this->checkIgnoreExtens=array_merge($this->ignoreExtens, $this->mageConfig['ignoreextens']);
if (isset ($this->mageConfig ['checkignoreextens'])) {
$this->checkIgnoreExtens = array_merge($this->ignoreExtens, $this->mageConfig['ignoreextens']);
}
/*
@ -258,15 +260,15 @@ class EncryptTask extends AbstractTask
* encrypt/encode file check
*
*/
if (isset ( $this->mageConfig ['checkignorepaths'])) {
$this->checkIgnorePaths=array_merge($this->checkIgnorePaths, $this->mageConfig['checkignorepaths']);
if (isset ($this->mageConfig ['checkignorepaths'])) {
$this->checkIgnorePaths = array_merge($this->checkIgnorePaths, $this->mageConfig['checkignorepaths']);
}
/*
* now merge all the config options together
*/
$this->ionCubeConfig = $this->mergeConfigFiles ();
$this->ionCubeConfig = $this->mergeConfigFiles();
}
/**
@ -283,29 +285,29 @@ class EncryptTask extends AbstractTask
/*
* Get a set of default IonCube options
*/
$this->default = $this->getOptionsDefault ();
$this->default = $this->getOptionsDefault();
/*
* Check if there is a 'project' section,
* if so then get the options from there
*/
if (isset ( $this->mageConfig ['project'] )) {
$this->yaml = $this->getOptionsFromYaml ( $this->mageConfig ['project'] );
if (isset ($this->mageConfig ['project'])) {
$this->yaml = $this->getOptionsFromYaml($this->mageConfig ['project']);
} else {
$this->yaml = array (
's' => array (),
'p' => array ()
$this->yaml = array(
's' => array(),
'p' => array()
);
}
/*
* Check if a seperate projectfile has been specified, and if so
* then read the options from there.
*/
if (isset ( $this->mageConfig ['projectfile'] )) {
$this->file = $this->getOptionsFromFile ( $this->mageConfig ['projectfile'] );
if (isset ($this->mageConfig ['projectfile'])) {
$this->file = $this->getOptionsFromFile($this->mageConfig ['projectfile']);
} else {
$this->file = array (
's' => array (),
'p' => array ()
$this->file = array(
's' => array(),
'p' => array()
);
}
}
@ -324,20 +326,21 @@ class EncryptTask extends AbstractTask
* @return bool
* @throws \Mage\Task\ErrorWithMessageException
*/
public function run() {
$this->switchSrcToTmp ();
$this->writeProjectFile ();
$result = $this->runIonCube ();
Console::output("Encoding result :".($result ? '<green>OK</green>' : '<red>Bad!</red>')."\n", 0, 2);
public function run()
{
$this->switchSrcToTmp();
$this->writeProjectFile();
$result = $this->runIonCube();
Console::output("Encoding result :" . ($result ? '<green>OK</green>' : '<red>Bad!</red>') . "\n", 0, 2);
if (!$result) {
$this->deleteTmpFiles ();
throw new ErrorWithMessageException('Ioncube failed to encode your project :'.$result);
$this->deleteTmpFiles();
throw new ErrorWithMessageException('Ioncube failed to encode your project :' . $result);
}
if (($this->checkEncoding) && (!$this->checkEncoding())) {
$this->deleteTmpFiles();
throw new ErrorWithMessageException('Operation canceled by user.');
}
$this->deleteTmpFiles ();
$this->deleteTmpFiles();
return $result;
}
@ -351,33 +354,34 @@ class EncryptTask extends AbstractTask
*
* @return bool
*/
private function checkEncoding() {
private function checkEncoding()
{
$src = $this->source;
// $ask holds flag to indicate we need to prompt the end user
$ask = false;
// scan through the directory
$rit = new \RecursiveDirectoryIterator ( $src );
foreach ( new \RecursiveIteratorIterator ( $rit ) as $filename => $cur ) {
$rit = new \RecursiveDirectoryIterator ($src);
foreach (new \RecursiveIteratorIterator ($rit) as $filename => $cur) {
// get the 'base dir' for the project, eg. relative to the temp folder
$srcFileName = (str_replace ( $this->source, '', $filename ));
$srcFileName = (str_replace($this->source, '', $filename));
/*
* Scan through the ignor directorys array
* and if it matches the current path/filename
* then mark the file to be skipped from testing
*/
$skip = false;
foreach ( $this->checkIgnorePaths as $path ) {
if (fnmatch ( $path, $srcFileName )) {
foreach ($this->checkIgnorePaths as $path) {
if (fnmatch($path, $srcFileName)) {
$skip = true;
}
}
// check if we should test this file
if (! $skip) {
if (!$skip) {
// get the file exten for this file and compare to our fileexten exclude array
$exten = pathinfo ( $filename, PATHINFO_EXTENSION );
if (! in_array ( strtolower ( $exten ), $this->checkIgnoreExtens )) {
$exten = pathinfo($filename, PATHINFO_EXTENSION);
if (!in_array(strtolower($exten), $this->checkIgnoreExtens)) {
// ok, this extension needs to be checked
if ($this->checkFileCoding ( $filename )) {
if ($this->checkFileCoding($filename)) {
// file was encrypted/encoded
} else {
// file was not encrypted/encoded
@ -390,7 +394,7 @@ class EncryptTask extends AbstractTask
if ($ask) {
// ok lets ask the user if they want to procede
Console::output("\n\nDo you wish to procede (y/N):", 0, 0);
if (! $this->promptYn ()) {
if (!$this->promptYn()) {
return false;
}
}
@ -407,10 +411,11 @@ class EncryptTask extends AbstractTask
*
* @return bool True if 'y' pressed
*/
private function promptYn() {
$handle = fopen ("php://stdin","r");
private function promptYn()
{
$handle = fopen("php://stdin", "r");
$line = strtolower(fgets($handle));
if(trim($line) != 'y'){
if (trim($line) != 'y') {
return false;
}
return true;
@ -428,23 +433,24 @@ class EncryptTask extends AbstractTask
*
* @return boolean True if file was encoded/encrypted
*/
private function checkFileCoding($filename) {
private function checkFileCoding($filename)
{
// check to see if this is an encrypted file
$ioncube = ioncube_read_file($filename, $ioncubeType);
if (is_int ( $ioncube )) {
if (is_int($ioncube)) {
// we got an error from ioncube, so its encrypted
return true;
}
// read first line of file
$f = fopen ( $filename, 'r' );
$line = trim ( fgets ( $f, 32 ) );
fclose ( $f );
$f = fopen($filename, 'r');
$line = trim(fgets($f, 32));
fclose($f);
// if first line is longer than 30, then this isnt a php file
if (strlen ( $line ) > 30) {
if (strlen($line) > 30) {
return false;
}
// if first line starts '<?php //0' then we can be pretty certain its encoded
if (substr ( $line, 0, 9 ) == '<?php //0') {
if (substr($line, 0, 9) == '<?php //0') {
return true;
}
// otherwise its most likley un-encrypted/encoded
@ -461,17 +467,18 @@ class EncryptTask extends AbstractTask
*
* @return void
*/
private function deleteTmpFiles() {
if (isset ( $this->mageConfig ['keeptemp'] )) {
private function deleteTmpFiles()
{
if (isset ($this->mageConfig ['keeptemp'])) {
return;
}
Console::log('Deleting tempory files :', 1);
$ret1 = Console::executeCommand ( 'rm -Rf ' . $this->ionSource, $out1 );
$ret2 = Console::executeCommand ( 'rm ' . $this->projectFile, $out2 );
$ret1 = Console::executeCommand('rm -Rf ' . $this->ionSource, $out1);
$ret2 = Console::executeCommand('rm ' . $this->projectFile, $out2);
if ($ret1 && $ret2) {
return;
}
throw new ErrorWithMessageException ( 'Error deleting temp files :' . $out1 . ' : ' . $out2, 40 );
throw new ErrorWithMessageException ('Error deleting temp files :' . $out1 . ' : ' . $out2, 40);
}
/**
@ -480,9 +487,10 @@ class EncryptTask extends AbstractTask
*
* @return bool
*/
private function runIonCube() {
$cli = $this->encoder . ' --project-file ' . $this->projectFile . ' ' . $this->ionSource . DIRECTORY_SEPARATOR.'*';
$ret = Console::executeCommand ( $cli, $out );
private function runIonCube()
{
$cli = $this->encoder . ' --project-file ' . $this->projectFile . ' ' . $this->ionSource . DIRECTORY_SEPARATOR . '*';
$ret = Console::executeCommand($cli, $out);
return $ret;
}
@ -495,37 +503,38 @@ class EncryptTask extends AbstractTask
*
* @return void
*/
private function writeProjectFile() {
private function writeProjectFile()
{
// array used to build config file into
$out = array ();
$out = array();
// set the project destination
$out [] = '--into ' . $this->source . PHP_EOL;
// output the switches
foreach ( $this->ionCubeConfig ['s'] as $key => $value ) {
foreach ($this->ionCubeConfig ['s'] as $key => $value) {
if ($value) {
// switch was set to true, so output it
$out [] = '--' . $key . PHP_EOL;
}
}
// output the options
foreach ( $this->ionCubeConfig ['p'] as $key => $value ) {
foreach ($this->ionCubeConfig ['p'] as $key => $value) {
// check if we have an array of values
if (is_array ( $value )) {
foreach ( $value as $entry ) {
if (is_array($value)) {
foreach ($value as $entry) {
$out [] = '--' . $key . ' "' . $entry . '"' . PHP_EOL;
}
} else {
// ok just a normal single option
if (strlen ( $value ) > 0) {
if (strlen($value) > 0) {
$out [] = '--' . $key . ' "' . $value . '"' . PHP_EOL;
}
}
}
$ret = file_put_contents ( $this->projectFile, $out );
if (! $ret) {
$ret = file_put_contents($this->projectFile, $out);
if (!$ret) {
// something went wrong
$this->deleteTmpFiles ();
throw new ErrorWithMessageException ( 'Unable to create project file.', 20 );
$this->deleteTmpFiles();
throw new ErrorWithMessageException ('Unable to create project file.', 20);
}
}
@ -535,7 +544,8 @@ class EncryptTask extends AbstractTask
*
* @return array Final config array
*/
private function mergeConfigFiles() {
private function mergeConfigFiles()
{
/*
* Options are the order the arrays are in
* F - Project File
@ -546,24 +556,24 @@ class EncryptTask extends AbstractTask
* @todo I'm sure this could be combined into a loop to make it easier and shorter
*
*/
$s = array ();
$p = array ();
switch (strtolower ( $this->ionOverRide )) {
$s = array();
$p = array();
switch (strtolower($this->ionOverRide)) {
case 'fyd' :
// FILE / YAML / DEFAULT
$s = array_merge ( $this->file ['s'], $this->yaml ['s'], $this->default ['s'] );
$p = array_merge ( $this->file ['p'], $this->yaml ['p'], $this->default ['p'] );
$s = array_merge($this->file ['s'], $this->yaml ['s'], $this->default ['s']);
$p = array_merge($this->file ['p'], $this->yaml ['p'], $this->default ['p']);
break;
case 'yfd' :
// YAML / FILE / DEFAULT
$s = array_merge ( $this->yaml ['s'], $this->file ['s'], $this->default ['s'] );
$p = array_merge ( $this->yaml ['p'], $this->file ['p'], $this->default ['p'] );
$s = array_merge($this->yaml ['s'], $this->file ['s'], $this->default ['s']);
$p = array_merge($this->yaml ['p'], $this->file ['p'], $this->default ['p']);
break;
case 'dyf' :
// DEFAULT / YAML / FILE
$s = array_merge ( $this->default ['s'], $this->yaml ['s'], $this->file ['s'] );
$p = array_merge ( $this->default ['p'], $this->yaml ['p'], $this->file ['p'] );
$s = array_merge($this->default ['s'], $this->yaml ['s'], $this->file ['s']);
$p = array_merge($this->default ['p'], $this->yaml ['p'], $this->file ['p']);
break;
case 'd' :
default :
@ -572,7 +582,7 @@ class EncryptTask extends AbstractTask
$p = $this->default ['p'];
break;
}
return array (
return array(
's' => $s,
'p' => $p
);
@ -591,14 +601,15 @@ class EncryptTask extends AbstractTask
*
* @return bool
*/
private function switchSrcToTmp() {
$ret = Console::executeCommand ( 'mv ' . $this->source . ' ' . $this->ionSource, $out );
if (! $ret) {
throw new ErrorWithMessageException ( 'Cant create tmp dir :' . $out, $ret );
private function switchSrcToTmp()
{
$ret = Console::executeCommand('mv ' . $this->source . ' ' . $this->ionSource, $out);
if (!$ret) {
throw new ErrorWithMessageException ('Cant create tmp dir :' . $out, $ret);
}
$ret = Console::executeCommand ( 'mkdir -p ' . $this->source, $out );
if (! $ret) {
throw new ErrorWithMessageException ( 'Cant re-create dir :' . $out, $ret );
$ret = Console::executeCommand('mkdir -p ' . $this->source, $out);
if (!$ret) {
throw new ErrorWithMessageException ('Cant re-create dir :' . $out, $ret);
}
return true;
}
@ -611,18 +622,19 @@ class EncryptTask extends AbstractTask
*
* return array
*/
private function getOptionsFromYaml($options) {
$s = array ();
$p = array ();
foreach ( $options as $key => $value ) {
if (array_key_exists ( $key, $this->default ['s'] )) {
private function getOptionsFromYaml($options)
{
$s = array();
$p = array();
foreach ($options as $key => $value) {
if (array_key_exists($key, $this->default ['s'])) {
$s [$key] = true;
}
if (array_key_exists ( $key, $this->default ['p'] )) {
if (array_key_exists($key, $this->default ['p'])) {
$p [$key] = $value;
}
}
return array (
return array(
's' => $s,
'p' => $p
);
@ -635,48 +647,49 @@ class EncryptTask extends AbstractTask
* @param $fileName
* @return array
*/
private function getOptionsFromFile($fileName) {
$s = array ();
$p = array ();
$fileContents = file_get_contents ( $fileName );
private function getOptionsFromFile($fileName)
{
$s = array();
$p = array();
$fileContents = file_get_contents($fileName);
/*
* split the config file on every occurance of '--' at start of a line
* Adds a PHP_EOL at the start, so we can catch the first '--'
*/
$entrys = explode ( PHP_EOL . '--', PHP_EOL . $fileContents );
foreach ( $entrys as $line ) {
$line = trim ( $line );
$entrys = explode(PHP_EOL . '--', PHP_EOL . $fileContents);
foreach ($entrys as $line) {
$line = trim($line);
if ($line != '') {
/*
* get position of first space
* so we can split the options out
*/
$str = strpos ( $line, ' ' );
$str = strpos($line, ' ');
if ($str === false) {
/*
* Ok, no spaces found, so take this as a single line
*/
$str = strlen ( $line );
$str = strlen($line);
}
$key = substr ( $line, $str );
$value = substr ( $line, $str + 1 );
if ((array_key_exists ( $key, $this->default ['s'] ))) {
$key = substr($line, $str);
$value = substr($line, $str + 1);
if ((array_key_exists($key, $this->default ['s']))) {
/*
* ok this key appears in the switch config
* so store it as a switch
*/
$s [$key] = true;
}
if ((array_key_exists ( $key, $this->default ['p'] ))) {
if ((array_key_exists($key, $this->default ['p']))) {
/*
* Ok this key exists in the parameter section,
* So store it allong with its value
*/
$p [$key] = $this->splitParam ( $value );
$p [$key] = $this->splitParam($value);
}
}
}
return array (
return array(
's' => $s,
'p' => $p
);
@ -693,13 +706,14 @@ class EncryptTask extends AbstractTask
*
* @return mixed
*/
private function splitParam($string) {
$split = explode ( PHP_EOL, $string );
private function splitParam($string)
{
$split = explode(PHP_EOL, $string);
if ($split === false) {
// nothing found, so return a blank string
return '';
}
if (count ( $split ) == 1) {
if (count($split) == 1) {
return $split [0];
} else {
return $split;
@ -715,9 +729,10 @@ class EncryptTask extends AbstractTask
*
* @return array
*/
private function getOptionsDefault() {
$s = array ();
$p = array ();
private function getOptionsDefault()
{
$s = array();
$p = array();
// Set the switches
$s ['allow-encoding-into-source'] = false;
@ -751,9 +766,9 @@ class EncryptTask extends AbstractTask
// Now set the params
$p ['encrypt'] [] = '*.tpl.html';
$p ['encode'] = array ();
$p ['copy'] = array ();
$p ['ignore'] = array (
$p ['encode'] = array();
$p ['copy'] = array();
$p ['ignore'] = array(
'.git',
'.svn',
getcwd() . '/.mage',
@ -761,7 +776,7 @@ class EncryptTask extends AbstractTask
'.gitkeep',
'nohup.out'
);
$p ['keep'] = array ();
$p ['keep'] = array();
$p ['obfuscate'] = '';
$p ['obfuscation-key'] = '';
$p ['obfuscation-exclusion-file'] = '';
@ -773,23 +788,23 @@ class EncryptTask extends AbstractTask
$p ['license-check'] = '';
$p ['apply-file-user'] = '';
$p ['apply-file-group'] = '';
$p ['register-autoglobal'] = array ();
$p ['register-autoglobal'] = array();
$p ['message-if-no-loader'] = '';
$p ['action-if-no-loader'] = '';
$p ['loader-path'] = '';
$p ['preamble-file'] = '';
$p ['add-comment'] = array ();
$p ['add-comment'] = array();
$p ['add-comments'] = '';
$p ['loader-event'] = array ();
$p ['loader-event'] = array();
$p ['callback-file'] = '';
$p ['property'] = '';
$p ['propertys'] = '';
$p ['include-if-property'] = array ();
$p ['include-if-property'] = array();
$p ['optimise'] = 'max';
$p ['shell-script-line'] = '';
$p ['min-loader-version'] = '';
return array (
return array(
's' => $s,
'p' => $p
);

View file

@ -59,7 +59,7 @@ class ListTask extends AbstractTask implements IsReleaseAware
foreach ($releases as $releaseIndex => $release) {
$release = trim($release);
$releaseIndex = str_pad($releaseIndex * -1, 2, ' ', STR_PAD_LEFT);
$releaseDate = $release[0] . $release[1] . $release[2] .$release[3]
$releaseDate = $release[0] . $release[1] . $release[2] . $release[3]
. '-'
. $release[4] . $release[5]
. '-'

View file

@ -56,7 +56,7 @@ class Factory
$instance = new $className($taskConfig, $inRollback, $stage, $taskParameters);
if (!is_a($instance,'Mage\Task\AbstractTask')) {
if (!is_a($instance, 'Mage\Task\AbstractTask')) {
throw new Exception('The Task ' . $taskName . ' must be an instance of Mage\Task\AbstractTask.');
}

View file

@ -34,7 +34,7 @@ class Dumper
*/
public function setIndentation($num)
{
$this->indentation = (int) $num;
$this->indentation = (int)$num;
}
/**
@ -54,7 +54,7 @@ class Dumper
$prefix = $indent ? str_repeat(' ', $indent) : '';
if ($inline <= 0 || !is_array($input) || empty($input)) {
$output .= $prefix.Inline::dump($input, $exceptionOnInvalidType, $objectSupport);
$output .= $prefix . Inline::dump($input, $exceptionOnInvalidType, $objectSupport);
} else {
$isAHash = array_keys($input) !== range(0, count($input) - 1);
@ -63,10 +63,10 @@ class Dumper
$output .= sprintf('%s%s%s%s',
$prefix,
$isAHash ? Inline::dump($key, $exceptionOnInvalidType, $objectSupport).':' : '-',
$isAHash ? Inline::dump($key, $exceptionOnInvalidType, $objectSupport) . ':' : '-',
$willBeInlined ? ' ' : "\n",
$this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $exceptionOnInvalidType, $objectSupport)
).($willBeInlined ? "\n" : '');
) . ($willBeInlined ? "\n" : '');
}
}

View file

@ -48,7 +48,7 @@ class Escaper
*/
public static function requiresDoubleQuoting($value)
{
return preg_match('/'.self::REGEX_CHARACTER_TO_ESCAPE.'/u', $value);
return preg_match('/' . self::REGEX_CHARACTER_TO_ESCAPE . '/u', $value);
}
/**

View file

@ -55,7 +55,7 @@ class Inline
return '';
}
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
if (function_exists('mb_internal_encoding') && ((int)ini_get('mbstring.func_overload')) & 2) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
}
@ -108,7 +108,7 @@ class Inline
return 'null';
case is_object($value):
if ($objectSupport) {
return '!!php/object:'.serialize($value);
return '!!php/object:' . serialize($value);
}
if ($exceptionOnInvalidType) {
@ -125,7 +125,7 @@ class Inline
case false === $value:
return 'false';
case ctype_digit($value):
return is_string($value) ? "'$value'" : (int) $value;
return is_string($value) ? "'$value'" : (int)$value;
case is_numeric($value):
$locale = setlocale(LC_NUMERIC, 0);
if (false !== $locale) {
@ -166,7 +166,9 @@ class Inline
// array
$keys = array_keys($value);
if ((1 == count($keys) && '0' == $keys[0])
|| (count($keys) > 1 && array_reduce($keys, function ($v, $w) { return (int) $v + $w; }, 0) == count($keys) * (count($keys) - 1) / 2)
|| (count($keys) > 1 && array_reduce($keys, function ($v, $w) {
return (int)$v + $w;
}, 0) == count($keys) * (count($keys) - 1) / 2)
) {
$output = array();
foreach ($value as $val) {
@ -220,7 +222,7 @@ class Inline
if (false !== $strpos = strpos($output, ' #')) {
$output = rtrim(substr($output, 0, $strpos));
}
} elseif (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
} elseif (preg_match('/^(.+?)(' . implode('|', $delimiters) . ')/', substr($scalar, $i), $match)) {
$output = $match[1];
$i += strlen($output);
} else {
@ -247,7 +249,7 @@ class Inline
*/
private static function parseQuotedScalar($scalar, &$i)
{
if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
if (!preg_match('/' . self::REGEX_QUOTED_STRING . '/Au', substr($scalar, $i), $match)) {
throw new ParseException(sprintf('Malformed inline YAML string (%s).', substr($scalar, $i)));
}
@ -304,7 +306,7 @@ class Inline
if (!$isQuoted && false !== strpos($value, ': ')) {
// embedded mapping?
try {
$value = self::parseMapping('{'.$value.'}');
$value = self::parseMapping('{' . $value . '}');
} catch (\InvalidArgumentException $e) {
// no, it's not
}
@ -346,7 +348,7 @@ class Inline
continue 2;
case '}':
if (self::$objectForMap) {
return (object) $output;
return (object)$output;
}
return $output;
@ -435,7 +437,7 @@ class Inline
case $scalar[0] === '+' || $scalar[0] === '-' || $scalar[0] === '.' || $scalar[0] === '!' || is_numeric($scalar[0]):
switch (true) {
case 0 === strpos($scalar, '!str'):
return (string) substr($scalar, 5);
return (string)substr($scalar, 5);
case 0 === strpos($scalar, '! '):
return intval(self::parseScalar(substr($scalar, 2)));
case 0 === strpos($scalar, '!!php/object:'):
@ -453,14 +455,14 @@ class Inline
$raw = $scalar;
$cast = intval($scalar);
return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
return '0' == $scalar[0] ? octdec($scalar) : (((string)$raw == (string)$cast) ? $cast : $raw);
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
$raw = $scalar;
$cast = intval($scalar);
return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
return '0' == $scalar[1] ? octdec($scalar) : (((string)$raw == (string)$cast) ? $cast : $raw);
case is_numeric($scalar):
return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar);
return '0x' == $scalar[0] . $scalar[1] ? hexdec($scalar) : floatval($scalar);
case '.inf' === $scalarLower:
case '.nan' === $scalarLower:
return -log(0);
@ -472,7 +474,7 @@ class Inline
return strtotime($scalar);
}
default:
return (string) $scalar;
return (string)$scalar;
}
}

View file

@ -61,7 +61,7 @@ class Parser
throw new ParseException('The YAML value does not appear to be valid UTF-8.');
}
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
if (function_exists('mb_internal_encoding') && ((int)ini_get('mbstring.func_overload')) & 2) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('UTF-8');
}
@ -99,7 +99,7 @@ class Parser
} else {
if (isset($values['leadspaces'])
&& ' ' == $values['leadspaces']
&& preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $values['value'], $matches)
&& preg_match('#^(?P<key>' . Inline::REGEX_QUOTED_STRING . '|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $values['value'], $matches)
) {
// this is a compact notation element, add to next block and parse
$c = $this->getRealCurrentLineNb();
@ -108,7 +108,7 @@ class Parser
$block = $values['value'];
if ($this->isNextLineIndented()) {
$block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
$block .= "\n" . $this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
}
$data[] = $parser->parse($block, $exceptionOnInvalidType, $objectSupport, $objectForMap);
@ -116,7 +116,7 @@ class Parser
$data[] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport, $objectForMap);
}
}
} elseif (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values) && false === strpos($values['key'],' #')) {
} elseif (preg_match('#^(?P<key>' . Inline::REGEX_QUOTED_STRING . '|[^ \'"\[\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values) && false === strpos($values['key'], ' #')) {
if ($context && 'sequence' == $context) {
throw new ParseException('You cannot define a mapping item when in a sequence');
}
@ -327,7 +327,7 @@ class Parser
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);
// Comments must not be removed inside a string block (ie. after a line ending with "|")
$removeCommentsPattern = '~'.self::FOLDED_SCALAR_PATTERN.'$~';
$removeCommentsPattern = '~' . self::FOLDED_SCALAR_PATTERN . '$~';
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
while ($this->moveToNextLine()) {
@ -417,7 +417,7 @@ class Parser
return $this->refs[$value];
}
if (preg_match('/^'.self::FOLDED_SCALAR_PATTERN.'$/', $value, $matches)) {
if (preg_match('/^' . self::FOLDED_SCALAR_PATTERN . '$/', $value, $matches)) {
$modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), intval(abs($modifiers)));

View file

@ -55,7 +55,7 @@ class Unescaper
};
// evaluate the string
return preg_replace_callback('/'.self::REGEX_ESCAPED_CHARACTER.'/u', $callback, $value);
return preg_replace_callback('/' . self::REGEX_ESCAPED_CHARACTER . '/u', $callback, $value);
}
/**
@ -131,12 +131,12 @@ class Unescaper
return chr($c);
}
if (0x800 > $c) {
return chr(0xC0 | $c>>6).chr(0x80 | $c & 0x3F);
return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
}
if (0x10000 > $c) {
return chr(0xE0 | $c>>12).chr(0x80 | $c>>6 & 0x3F).chr(0x80 | $c & 0x3F);
return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
}
return chr(0xF0 | $c>>18).chr(0x80 | $c>>12 & 0x3F).chr(0x80 | $c>>6 & 0x3F).chr(0x80 | $c & 0x3F);
return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
}
}