Browse Source

PHPStorm refactoring.

1.0
Andrés Montañez 11 years ago
parent
commit
fddeebe59a
  1. 3
      Mage/Autoload.php
  2. 3
      Mage/Command/BuiltIn/InstallCommand.php
  3. 18
      Mage/Config.php
  4. 6
      Mage/Mailer.php
  5. 45
      Mage/Task/BuiltIn/Ioncube/EncryptTask.php
  6. 4
      Mage/Yaml/Inline.php

3
Mage/Autoload.php

@ -30,8 +30,7 @@ class Autoload
//Try to load a normal Mage class (or Task). Think that Mage component is compiled to .phar //Try to load a normal Mage class (or Task). Think that Mage component is compiled to .phar
$baseDir = dirname(dirname(__FILE__)); $baseDir = dirname(dirname(__FILE__));
$classFileWithinPhar = $baseDir . $postfix; $classFileWithinPhar = $baseDir . $postfix;
if($this->isReadable($classFileWithinPhar)) if ($this->isReadable($classFileWithinPhar)) {
{
/** @noinspection PhpIncludeInspection */ /** @noinspection PhpIncludeInspection */
require_once $classFileWithinPhar; require_once $classFileWithinPhar;
return true; return true;

3
Mage/Command/BuiltIn/InstallCommand.php

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

18
Mage/Config.php

@ -116,7 +116,8 @@ class Config
* @return array * @return array
* @throws Config\ConfigNotFoundException * @throws Config\ConfigNotFoundException
*/ */
protected function loadGeneral($filePath){ protected function loadGeneral($filePath)
{
return $this->parseConfigFile($filePath); return $this->parseConfigFile($filePath);
} }
@ -142,6 +143,7 @@ class Config
return $settings; return $settings;
} }
/** /**
* Loads the Environment configuration * Loads the Environment configuration
* @param $filePath string * @param $filePath string
@ -171,8 +173,7 @@ class Config
{ {
$environment = $this->getEnvironment(); $environment = $this->getEnvironment();
if(!empty($environment)) if (!empty($environment)) {
{
$configFilePath = getcwd() . '/.mage/config/environment/' . $environment . '.yml'; $configFilePath = getcwd() . '/.mage/config/environment/' . $environment . '.yml';
try { try {
@ -193,16 +194,15 @@ class Config
{ {
if (empty($parameters)) if (empty($parameters))
return true; return true;
foreach($parameters as $parameter) foreach ($parameters as $parameter) {
{ if (isset(Console::$paramsNotRequiringEnvironment[$parameter])) {
if(isset(Console::$paramsNotRequiringEnvironment[$parameter]))
{
return true; return true;
} }
} }
return false; return false;
} }
/** /**
* Load the Configuration and parses the Arguments * Load the Configuration and parses the Arguments
* *
@ -575,13 +575,13 @@ class Config
*/ */
public function parseConfigFile($filePath) public function parseConfigFile($filePath)
{ {
if(!file_exists($filePath)) if (!file_exists($filePath)) {
{
throw new ConfigNotFoundException("Cannot find the file at path $filePath"); throw new ConfigNotFoundException("Cannot find the file at path $filePath");
} }
return $this->parseConfigText(file_get_contents($filePath)); return $this->parseConfigText(file_get_contents($filePath));
} }
public function parseConfigText($input) public function parseConfigText($input)
{ {
return Yaml::parse($input); return Yaml::parse($input);

6
Mage/Mailer.php

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

45
Mage/Task/BuiltIn/Ioncube/EncryptTask.php

@ -171,7 +171,8 @@ class EncryptTask extends AbstractTask
* *
* @see \Mage\Task\AbstractTask::getName() * @see \Mage\Task\AbstractTask::getName()
*/ */
public function getName() { public function getName()
{
return $this->name; return $this->name;
} }
@ -180,7 +181,8 @@ class EncryptTask extends AbstractTask
* *
* @see \Mage\Task\AbstractTask::init() * @see \Mage\Task\AbstractTask::init()
*/ */
public function init() { public function init()
{
// Set the default extensions to ignore // Set the default extensions to ignore
$this->checkIgnoreExtens = array( $this->checkIgnoreExtens = array(
'jpg', 'jpg',
@ -324,7 +326,8 @@ class EncryptTask extends AbstractTask
* @return bool * @return bool
* @throws \Mage\Task\ErrorWithMessageException * @throws \Mage\Task\ErrorWithMessageException
*/ */
public function run() { public function run()
{
$this->switchSrcToTmp(); $this->switchSrcToTmp();
$this->writeProjectFile(); $this->writeProjectFile();
$result = $this->runIonCube(); $result = $this->runIonCube();
@ -351,7 +354,8 @@ class EncryptTask extends AbstractTask
* *
* @return bool * @return bool
*/ */
private function checkEncoding() { private function checkEncoding()
{
$src = $this->source; $src = $this->source;
// $ask holds flag to indicate we need to prompt the end user // $ask holds flag to indicate we need to prompt the end user
$ask = false; $ask = false;
@ -407,7 +411,8 @@ class EncryptTask extends AbstractTask
* *
* @return bool True if 'y' pressed * @return bool True if 'y' pressed
*/ */
private function promptYn() { private function promptYn()
{
$handle = fopen("php://stdin", "r"); $handle = fopen("php://stdin", "r");
$line = strtolower(fgets($handle)); $line = strtolower(fgets($handle));
if (trim($line) != 'y') { if (trim($line) != 'y') {
@ -428,7 +433,8 @@ class EncryptTask extends AbstractTask
* *
* @return boolean True if file was encoded/encrypted * @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 // check to see if this is an encrypted file
$ioncube = ioncube_read_file($filename, $ioncubeType); $ioncube = ioncube_read_file($filename, $ioncubeType);
if (is_int($ioncube)) { if (is_int($ioncube)) {
@ -461,7 +467,8 @@ class EncryptTask extends AbstractTask
* *
* @return void * @return void
*/ */
private function deleteTmpFiles() { private function deleteTmpFiles()
{
if (isset ($this->mageConfig ['keeptemp'])) { if (isset ($this->mageConfig ['keeptemp'])) {
return; return;
} }
@ -480,7 +487,8 @@ class EncryptTask extends AbstractTask
* *
* @return bool * @return bool
*/ */
private function runIonCube() { private function runIonCube()
{
$cli = $this->encoder . ' --project-file ' . $this->projectFile . ' ' . $this->ionSource . DIRECTORY_SEPARATOR . '*'; $cli = $this->encoder . ' --project-file ' . $this->projectFile . ' ' . $this->ionSource . DIRECTORY_SEPARATOR . '*';
$ret = Console::executeCommand($cli, $out); $ret = Console::executeCommand($cli, $out);
return $ret; return $ret;
@ -495,7 +503,8 @@ class EncryptTask extends AbstractTask
* *
* @return void * @return void
*/ */
private function writeProjectFile() { private function writeProjectFile()
{
// array used to build config file into // array used to build config file into
$out = array(); $out = array();
// set the project destination // set the project destination
@ -535,7 +544,8 @@ class EncryptTask extends AbstractTask
* *
* @return array Final config array * @return array Final config array
*/ */
private function mergeConfigFiles() { private function mergeConfigFiles()
{
/* /*
* Options are the order the arrays are in * Options are the order the arrays are in
* F - Project File * F - Project File
@ -591,7 +601,8 @@ class EncryptTask extends AbstractTask
* *
* @return bool * @return bool
*/ */
private function switchSrcToTmp() { private function switchSrcToTmp()
{
$ret = Console::executeCommand('mv ' . $this->source . ' ' . $this->ionSource, $out); $ret = Console::executeCommand('mv ' . $this->source . ' ' . $this->ionSource, $out);
if (!$ret) { if (!$ret) {
throw new ErrorWithMessageException ('Cant create tmp dir :' . $out, $ret); throw new ErrorWithMessageException ('Cant create tmp dir :' . $out, $ret);
@ -611,7 +622,8 @@ class EncryptTask extends AbstractTask
* *
* return array * return array
*/ */
private function getOptionsFromYaml($options) { private function getOptionsFromYaml($options)
{
$s = array(); $s = array();
$p = array(); $p = array();
foreach ($options as $key => $value) { foreach ($options as $key => $value) {
@ -635,7 +647,8 @@ class EncryptTask extends AbstractTask
* @param $fileName * @param $fileName
* @return array * @return array
*/ */
private function getOptionsFromFile($fileName) { private function getOptionsFromFile($fileName)
{
$s = array(); $s = array();
$p = array(); $p = array();
$fileContents = file_get_contents($fileName); $fileContents = file_get_contents($fileName);
@ -693,7 +706,8 @@ class EncryptTask extends AbstractTask
* *
* @return mixed * @return mixed
*/ */
private function splitParam($string) { private function splitParam($string)
{
$split = explode(PHP_EOL, $string); $split = explode(PHP_EOL, $string);
if ($split === false) { if ($split === false) {
// nothing found, so return a blank string // nothing found, so return a blank string
@ -715,7 +729,8 @@ class EncryptTask extends AbstractTask
* *
* @return array * @return array
*/ */
private function getOptionsDefault() { private function getOptionsDefault()
{
$s = array(); $s = array();
$p = array(); $p = array();
// Set the switches // Set the switches

4
Mage/Yaml/Inline.php

@ -166,7 +166,9 @@ class Inline
// array // array
$keys = array_keys($value); $keys = array_keys($value);
if ((1 == count($keys) && '0' == $keys[0]) 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(); $output = array();
foreach ($value as $val) { foreach ($value as $val) {

Loading…
Cancel
Save