From 191a120aa5765423901286d2f250121d36b2ebd3 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 10 Mar 2014 12:03:57 +0100 Subject: [PATCH] remove unused class and change function name to be PSR1 compliant --- .../Admin/TranslationsController.php | 2 +- .../Template/Smarty/AbstractSmartyPlugin.php | 6 +- .../Smarty/Plugins/AdminUtilities.php | 6 +- .../Core/Template/Smarty/Plugins/Security.php | 8 +- .../Thelia/Core/Template/TemplateHelper.php | 6 +- core/lib/Thelia/Tools/DIGenerator.php | 132 ------------------ 6 files changed, 14 insertions(+), 146 deletions(-) delete mode 100644 core/lib/Thelia/Tools/DIGenerator.php diff --git a/core/lib/Thelia/Controller/Admin/TranslationsController.php b/core/lib/Thelia/Controller/Admin/TranslationsController.php index ab31f4406..453e32485 100644 --- a/core/lib/Thelia/Controller/Admin/TranslationsController.php +++ b/core/lib/Thelia/Controller/Admin/TranslationsController.php @@ -117,7 +117,7 @@ class TranslationsController extends BaseAdminController $translations = $this->getRequest()->get('translation', array()); - TemplateHelper::getInstance()->write_translation($file, $texts, $translations); + TemplateHelper::getInstance()->writeTranslation($file, $texts, $translations); if ($save_mode == 'stay') $this->redirectToRoute("admin.configuration.translations", $templateArguments); diff --git a/core/lib/Thelia/Core/Template/Smarty/AbstractSmartyPlugin.php b/core/lib/Thelia/Core/Template/Smarty/AbstractSmartyPlugin.php index a0ef6601a..57227d894 100644 --- a/core/lib/Thelia/Core/Template/Smarty/AbstractSmartyPlugin.php +++ b/core/lib/Thelia/Core/Template/Smarty/AbstractSmartyPlugin.php @@ -35,10 +35,10 @@ abstract class AbstractSmartyPlugin /** * Explode a comma separated list in a array, trimming all array elements * - * @param unknown $commaSeparatedValues - * @return multitype: + * @param mixed $commaSeparatedValues + * @return mixed: */ - protected function _explode($commaSeparatedValues) + protected function explode($commaSeparatedValues) { if (null === $commaSeparatedValues) { return array(); diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php index 8b8ee8ef1..283a4c6cf 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php @@ -43,7 +43,7 @@ class AdminUtilities extends AbstractSmartyPlugin $this->securityContext = $securityContext; } - protected function fetch_snippet($smarty, $templateName, $variablesArray) + protected function fetchSnippet($smarty, $templateName, $variablesArray) { $data = ''; @@ -97,7 +97,7 @@ class AdminUtilities extends AbstractSmartyPlugin $module === null ? array() : array($module), array($access)) ) { - return $this->fetch_snippet($smarty, 'includes/admin-utilities-position-block', array( + return $this->fetchSnippet($smarty, 'includes/admin-utilities-position-block', array( 'admin_utilities_go_up_url' => URL::getInstance()->absoluteUrl($path, array('mode' => 'up', $url_parameter => $id)), 'admin_utilities_in_place_edit_class' => $in_place_edit_class, 'admin_utilities_object_id' => $id, @@ -146,7 +146,7 @@ class AdminUtilities extends AbstractSmartyPlugin $order_change = $order; } - return $this->fetch_snippet($smarty, 'includes/admin-utilities-sortable-column-header', array( + return $this->fetchSnippet($smarty, 'includes/admin-utilities-sortable-column-header', array( 'admin_utilities_sort_direction' => $sort_direction, 'admin_utilities_sorting_url' => URL::getInstance()->absoluteUrl($path, array($request_parameter_name => $order_change)), 'admin_utilities_header_text' => $label diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php index 46a45c0c4..9db8e90fe 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php @@ -53,10 +53,10 @@ class Security extends AbstractSmartyPlugin */ public function checkAuthFunction($params, &$smarty) { - $roles = $this->_explode($this->getParam($params, 'role')); - $resources = $this->_explode($this->getParam($params, 'resource')); - $modules = $this->_explode($this->getParam($params, 'module')); - $accesses = $this->_explode($this->getParam($params, 'access')); + $roles = $this->explode($this->getParam($params, 'role')); + $resources = $this->explode($this->getParam($params, 'resource')); + $modules = $this->explode($this->getParam($params, 'module')); + $accesses = $this->explode($this->getParam($params, 'access')); if (! $this->securityContext->isGranted($roles, $resources, $modules, $accesses)) { diff --git a/core/lib/Thelia/Core/Template/TemplateHelper.php b/core/lib/Thelia/Core/Template/TemplateHelper.php index c08d94c0a..4a5352f0a 100644 --- a/core/lib/Thelia/Core/Template/TemplateHelper.php +++ b/core/lib/Thelia/Core/Template/TemplateHelper.php @@ -139,7 +139,7 @@ class TemplateHelper } } - protected function normalize_path($path) + protected function normalizePath($path) { $path = str_replace( str_replace('\\', '/', THELIA_ROOT), @@ -203,7 +203,7 @@ class TemplateHelper if ($content = file_get_contents($fileInfo->getPathName())) { - $short_path = $this->normalize_path($fileInfo->getPathName()); + $short_path = $this->normalizePath($fileInfo->getPathName()); Tlog::getInstance()->debug("Examining file $short_path\n"); @@ -249,7 +249,7 @@ class TemplateHelper } - public function write_translation($file, $texts, $translations) + public function writeTranslation($file, $texts, $translations) { if ($fp = @fopen($file, 'w')) { diff --git a/core/lib/Thelia/Tools/DIGenerator.php b/core/lib/Thelia/Tools/DIGenerator.php deleted file mode 100644 index f18338d5b..000000000 --- a/core/lib/Thelia/Tools/DIGenerator.php +++ /dev/null @@ -1,132 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ -namespace Thelia\Tools; - -class DIGenerator -{ - /** - * Find all models in a directory - * - * @param string $directory Directory where models have to be find. - * @param array $exclude Model to be exclude in the return - * - * @return array key is the service name and value the full Class name (including namespace if needed) - * - * @throws \RuntimeException id $directory is not a valid directory - * - */ - public static function genDiModel($directory, array $exclude = array()) - { - if(!is_string($directory)) return array(); - - if (!is_dir($directory)) { - throw new \RuntimeException($directory." is not a valid directory"); - } - - $results = array(); - - $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)); - - foreach ($files as $file) { - //$file is instance of SplFileInfo - if(!$file->isFile()) continue; - - $filePath = $file->getRealPath(); - - $classes = self::findClasses($filePath); - - foreach ($classes as $class) { - $classInfo = new \ReflectionClass($class); - $shortName = $classInfo->getShortName(); - if (!in_array($shortName, $exclude)) { - $results[$shortName] = $class; - } - } - } - - return $results; - - } - - /** - * Extract the classes in the given file - * - * copied from Composer\Autoload\GenerateClassMap::findClasses() - * - * @param string $path The file to check - * - * @return array The found classes - */ - private static function findClasses($path) - { - $traits = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait'; - - try { - $contents = php_strip_whitespace($path); - } catch (\Exception $e) { - throw new \RuntimeException('Could not scan for classes inside '.$path.": \n".$e->getMessage(), 0, $e); - } - - // return early if there is no chance of matching anything in this file - if (!preg_match('{\b(?:class|interface'.$traits.')\b}i', $contents)) { - return array(); - } - - // strip heredocs/nowdocs - $contents = preg_replace('{<<<\'?(\w+)\'?(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r)\\1(?=\r\n|\n|\r|;)}s', 'null', $contents); - // strip strings - $contents = preg_replace('{"[^"\\\\]*(\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(\\\\.[^\'\\\\]*)*\'}', 'null', $contents); - // strip leading non-php code if needed - if (substr($contents, 0, 2) !== '.+<\?}s', '?>'); - if (false !== $pos && false === strpos(substr($contents, $pos), '])(?Pclass|interface'.$traits.') \s+ (?P[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*) - | \b(?])(?Pnamespace) (?P\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(?:\s*\\\\\s*[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*)? \s*[\{;] - ) - }ix', $contents, $matches); - - $classes = array(); - $namespace = ''; - - for ($i = 0, $len = count($matches['type']); $i < $len; $i++) { - if (!empty($matches['ns'][$i])) { - $namespace = str_replace(array(' ', "\t", "\r", "\n"), '', $matches['nsname'][$i]) . '\\'; - } else { - $classes[] = ltrim($namespace . $matches['name'][$i], '\\'); - } - } - - return $classes; - } - -}