From ffdc933d9a4294cbbc28604a84fd1d951607db9a Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sat, 18 Jul 2015 18:43:14 +0200 Subject: [PATCH 1/5] Php Inspections (EA Extended): SCA --- lib/addon/sfPager.class.php | 2 +- lib/cache/sfFileCache.class.php | 6 +- lib/cache/sfMemcacheCache.class.php | 4 +- lib/cache/sfSQLiteCache.class.php | 6 +- lib/config/sfAutoloadConfigHandler.class.php | 2 +- lib/config/sfPluginConfiguration.class.php | 40 ++++----- lib/config/sfRootConfigHandler.class.php | 2 +- lib/config/sfRoutingConfigHandler.class.php | 2 +- lib/debug/sfWebDebug.class.php | 2 +- lib/debug/sfWebDebugPanelView.class.php | 58 ++++++------- lib/form/sfForm.class.php | 4 +- .../sfModelGeneratorConfiguration.class.php | 4 +- lib/helper/AssetHelper.php | 4 +- lib/helper/DateHelper.php | 2 +- lib/helper/JavascriptBaseHelper.php | 4 +- lib/helper/NumberHelper.php | 2 +- lib/helper/TagHelper.php | 2 +- lib/helper/UrlHelper.php | 36 ++++---- lib/i18n/Gettext/MO.php | 86 +++++++++---------- lib/i18n/Gettext/PO.php | 28 +++--- lib/i18n/Gettext/TGettext.class.php | 60 ++++++------- lib/i18n/sfChoiceFormat.class.php | 18 ++-- lib/i18n/sfDateFormat.class.php | 46 +++++----- lib/i18n/sfMessageSource_File.class.php | 2 +- lib/i18n/sfMessageSource_MySQL.class.php | 32 +++---- lib/i18n/sfMessageSource_SQLite.class.php | 22 ++--- lib/i18n/sfMessageSource_SQLite3.class.php | 8 +- lib/i18n/sfMessageSource_XLIFF.class.php | 2 +- lib/i18n/sfNumberFormat.class.php | 20 ++--- lib/request/sfRequest.class.php | 7 +- lib/request/sfWebRequest.class.php | 4 +- lib/routing/sfPatternRouting.class.php | 2 +- ...sfServiceContainerDumperGraphviz.class.php | 4 +- lib/storage/sfCacheSessionStorage.class.php | 12 +-- .../sfDatabaseSessionStorage.class.php | 10 ++- lib/storage/sfSessionTestStorage.class.php | 2 +- .../generator/sfGenerateAppTask.class.php | 2 +- lib/task/help/sfListTask.class.php | 6 +- lib/task/plugin/sfPluginListTask.class.php | 4 +- .../sfPluginPublishAssetsTask.class.php | 6 +- lib/task/sfBaseTask.class.php | 6 +- lib/task/sfFilesystem.class.php | 2 +- lib/task/sfTask.class.php | 12 +-- lib/util/sfBrowserBase.class.php | 7 +- lib/util/sfDomCssSelector.class.php | 4 +- lib/util/sfToolkit.class.php | 4 +- lib/validator/sfValidatedFile.class.php | 2 +- lib/validator/sfValidatorBase.class.php | 2 +- lib/validator/sfValidatorDate.class.php | 22 ++--- lib/validator/sfValidatorInteger.class.php | 4 +- lib/validator/sfValidatorNumber.class.php | 2 +- lib/validator/sfValidatorTime.class.php | 8 +- lib/widget/sfWidgetForm.class.php | 2 +- lib/widget/sfWidgetFormSchema.class.php | 2 +- .../sfWidgetFormSchemaFormatter.class.php | 2 +- lib/widget/sfWidgetFormSelect.class.php | 4 +- .../sfWidgetFormSelectCheckbox.class.php | 2 +- lib/widget/sfWidgetFormSelectRadio.class.php | 2 +- lib/yaml/sfYamlInline.class.php | 18 ++-- lib/yaml/sfYamlParser.class.php | 2 +- 60 files changed, 335 insertions(+), 339 deletions(-) diff --git a/lib/addon/sfPager.class.php b/lib/addon/sfPager.class.php index 819998bd2..a7d56a037 100644 --- a/lib/addon/sfPager.class.php +++ b/lib/addon/sfPager.class.php @@ -380,7 +380,7 @@ public function getPreviousPage() */ public function setPage($page) { - $this->page = intval($page); + $this->page = (int) $page; if ($this->page <= 0) { diff --git a/lib/cache/sfFileCache.class.php b/lib/cache/sfFileCache.class.php index e78d66d82..19c0ac4cb 100644 --- a/lib/cache/sfFileCache.class.php +++ b/lib/cache/sfFileCache.class.php @@ -83,7 +83,7 @@ public function has($key) */ public function set($key, $data, $lifetime = null) { - if ($this->getOption('automatic_cleaning_factor') > 0 && rand(1, $this->getOption('automatic_cleaning_factor')) == 1) + if ($this->getOption('automatic_cleaning_factor') > 0 && mt_rand(1, $this->getOption('automatic_cleaning_factor')) == 1) { $this->clean(sfCache::OLD); } @@ -235,12 +235,12 @@ protected function read($path, $type = self::READ_DATA) } @flock($fp, LOCK_SH); - $data[self::READ_TIMEOUT] = intval(@stream_get_contents($fp, 12, 0)); + $data[self::READ_TIMEOUT] = (int) @stream_get_contents($fp, 12, 0); if ($type != self::READ_TIMEOUT && time() < $data[self::READ_TIMEOUT]) { if ($type & self::READ_LAST_MODIFIED) { - $data[self::READ_LAST_MODIFIED] = intval(@stream_get_contents($fp, 12, 12)); + $data[self::READ_LAST_MODIFIED] = (int) @stream_get_contents($fp, 12, 12); } if ($type & self::READ_DATA) { diff --git a/lib/cache/sfMemcacheCache.class.php b/lib/cache/sfMemcacheCache.class.php index e438f8001..dc66e12b8 100644 --- a/lib/cache/sfMemcacheCache.class.php +++ b/lib/cache/sfMemcacheCache.class.php @@ -3,7 +3,7 @@ /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -60,7 +60,7 @@ public function initialize($options = array()) foreach ($this->getOption('servers') as $server) { $port = isset($server['port']) ? $server['port'] : 11211; - if (!$this->memcache->addServer($server['host'], $port, isset($server['persistent']) ? $server['persistent'] : true)) + if (!$this->memcache->addserver($server['host'], $port, isset($server['persistent']) ? $server['persistent'] : true)) { throw new sfInitializationException(sprintf('Unable to connect to the memcache server (%s:%s).', $server['host'], $port)); } diff --git a/lib/cache/sfSQLiteCache.class.php b/lib/cache/sfSQLiteCache.class.php index 3c7691a7c..61916037b 100644 --- a/lib/cache/sfSQLiteCache.class.php +++ b/lib/cache/sfSQLiteCache.class.php @@ -94,7 +94,7 @@ public function has($key) */ public function set($key, $data, $lifetime = null) { - if ($this->getOption('automatic_cleaning_factor') > 0 && rand(1, $this->getOption('automatic_cleaning_factor')) == 1) + if ($this->getOption('automatic_cleaning_factor') > 0 && mt_rand(1, $this->getOption('automatic_cleaning_factor')) == 1) { $this->clean(sfCache::OLD); } @@ -167,7 +167,7 @@ public function getTimeout($key) $rs = $this->dbh->query(sprintf("SELECT timeout FROM cache WHERE key = '%s' AND timeout > %d", sqlite_escape_string($key), time())); - return $rs->numRows() ? intval($rs->fetchSingle()) : 0; + return $rs->numRows() ? (int) $rs->fetchSingle() : 0; } /** @@ -184,7 +184,7 @@ public function getLastModified($key) $rs = $this->dbh->query(sprintf("SELECT last_modified FROM cache WHERE key = '%s' AND timeout > %d", sqlite_escape_string($key), time())); - return $rs->numRows() ? intval($rs->fetchSingle()) : 0; + return $rs->numRows() ? (int) $rs->fetchSingle() : 0; } /** diff --git a/lib/config/sfAutoloadConfigHandler.class.php b/lib/config/sfAutoloadConfigHandler.class.php index 4a393e102..cf0f8e15b 100644 --- a/lib/config/sfAutoloadConfigHandler.class.php +++ b/lib/config/sfAutoloadConfigHandler.class.php @@ -160,7 +160,7 @@ static public function getConfiguration(array $configFiles) foreach ($configFiles as $i => $configFile) { $configFilePath = str_replace(DIRECTORY_SEPARATOR, '/', $configFile); - $path = str_replace(DIRECTORY_SEPARATOR, '/', realpath(join('/', array_slice(explode('/', $configFilePath), 0, -2)))); + $path = str_replace(DIRECTORY_SEPARATOR, '/', realpath(implode('/', array_slice(explode('/', $configFilePath), 0, -2)))); if (in_array($path, $pluginPaths)) { $pluginConfigFiles[] = $configFile; diff --git a/lib/config/sfPluginConfiguration.class.php b/lib/config/sfPluginConfiguration.class.php index 8b170efce..028261837 100644 --- a/lib/config/sfPluginConfiguration.class.php +++ b/lib/config/sfPluginConfiguration.class.php @@ -3,14 +3,14 @@ /* * This file is part of the symfony package. * (c) Fabien Potencier - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * sfPluginConfiguration represents a configuration for a symfony plugin. - * + * * @package symfony * @subpackage config * @author Kris Wallsmith @@ -26,7 +26,7 @@ abstract class sfPluginConfiguration /** * Constructor. - * + * * @param sfProjectConfiguration $configuration The project configuration * @param string $rootDir The plugin root directory * @param string $name The plugin name @@ -50,7 +50,7 @@ public function __construct(sfProjectConfiguration $configuration, $rootDir = nu /** * Sets up the plugin. - * + * * This method can be used when creating a base plugin configuration class for other plugins to extend. */ public function setup() @@ -59,7 +59,7 @@ public function setup() /** * Configures the plugin. - * + * * This method is called before the plugin's classes have been added to sfAutoload. */ public function configure() @@ -68,9 +68,9 @@ public function configure() /** * Initializes the plugin. - * + * * This method is called after the plugin's classes have been added to sfAutoload. - * + * * @return boolean|null If false sfApplicationConfiguration will look for a config.php (maintains BC with symfony < 1.2) */ public function initialize() @@ -79,7 +79,7 @@ public function initialize() /** * Returns the plugin root directory. - * + * * @return string */ public function getRootDir() @@ -89,7 +89,7 @@ public function getRootDir() /** * Returns the plugin name. - * + * * @return string */ public function getName() @@ -99,11 +99,11 @@ public function getName() /** * Initializes autoloading for the plugin. - * + * * This method is called when a plugin is initialized in a project * configuration. Otherwise, autoload is handled in * {@link sfApplicationConfiguration} using {@link sfAutoload}. - * + * * @see sfSimpleAutoload */ public function initializeAutoload() @@ -126,10 +126,10 @@ public function initializeAutoload() /** * Filters sfAutoload configuration values. - * - * @param sfEvent $event - * @param array $config - * + * + * @param sfEvent $event + * @param array $config + * * @return array */ public function filterAutoloadConfig(sfEvent $event, array $config) @@ -169,10 +169,10 @@ public function connectTests() /** * Listens for the "task.test.filter_test_files" event and adds tests from the current plugin. - * + * * @param sfEvent $event * @param array $files - * + * * @return array An array of files with the appropriate tests from the current plugin merged in */ public function filterTestFiles(sfEvent $event, $files) @@ -211,18 +211,18 @@ public function filterTestFiles(sfEvent $event, $files) /** * Guesses the plugin root directory. - * + * * @return string */ protected function guessRootDir() { $r = new ReflectionClass(get_class($this)); - return realpath(dirname($r->getFilename()).'/..'); + return realpath(dirname($r->getFileName()).'/..'); } /** * Guesses the plugin name. - * + * * @return string */ protected function guessName() diff --git a/lib/config/sfRootConfigHandler.class.php b/lib/config/sfRootConfigHandler.class.php index 42707352b..c48102988 100644 --- a/lib/config/sfRootConfigHandler.class.php +++ b/lib/config/sfRootConfigHandler.class.php @@ -35,7 +35,7 @@ public function execute($configFiles) $config = static::getConfiguration($configFiles); // determine if we're loading the system config_handlers.yml or a module config_handlers.yml - $moduleLevel = ($this->getParameterHolder()->get('module_level') === true) ? true : false; + $moduleLevel = ($this->getParameterHolder()->get('module_level') === true); if ($moduleLevel) { diff --git a/lib/config/sfRoutingConfigHandler.class.php b/lib/config/sfRoutingConfigHandler.class.php index f7c032bbb..0c485f48b 100644 --- a/lib/config/sfRoutingConfigHandler.class.php +++ b/lib/config/sfRoutingConfigHandler.class.php @@ -95,7 +95,7 @@ protected function parse($configFiles) else { $routes[$name] = array(isset($params['class']) ? $params['class'] : 'sfRoute', array( - $params['url'] ? $params['url'] : '/', + $params['url'] ?: '/', isset($params['params']) ? $params['params'] : (isset($params['param']) ? $params['param'] : array()), isset($params['requirements']) ? $params['requirements'] : array(), isset($params['options']) ? $params['options'] : array(), diff --git a/lib/debug/sfWebDebug.class.php b/lib/debug/sfWebDebug.class.php index d3c7ebaa8..b511da093 100644 --- a/lib/debug/sfWebDebug.class.php +++ b/lib/debug/sfWebDebug.class.php @@ -207,7 +207,7 @@ public function asHtml() $titles[] = sprintf('%s', $panel->getStatus() ? ' class="sfWebDebug'.ucfirst($this->getPriority($panel->getStatus())).'"' : '', $panel->getPanelTitle(), - $panel->getTitleUrl() ? $panel->getTitleUrl() : '#', + $panel->getTitleUrl() ?: '#', $panel->getTitleUrl() ? '' : ' onclick="sfWebDebugShowDetailsFor(\''.$id.'\'); return false;"', $title ); diff --git a/lib/debug/sfWebDebugPanelView.class.php b/lib/debug/sfWebDebugPanelView.class.php index 168c74e32..bab2b3712 100644 --- a/lib/debug/sfWebDebugPanelView.class.php +++ b/lib/debug/sfWebDebugPanelView.class.php @@ -10,7 +10,7 @@ /** * sfWebDebugPanelView adds a panel to the web debug toolbar with information about the view layer. - * + * * @package symfony * @subpackage debug * @author Kris Wallsmith @@ -37,7 +37,7 @@ public function __construct(sfWebDebug $webDebug) /** * Resets the parameter collections. - * + * * @param sfEvent $event */ public function listenForChangeAction(sfEvent $event) @@ -48,10 +48,10 @@ public function listenForChangeAction(sfEvent $event) /** * Stacks action and partial parameters in the template.filter_parameters event. - * + * * @param sfEvent $event * @param array $parameters - * + * * @return array */ public function filterTemplateParameters(sfEvent $event, $parameters) @@ -72,9 +72,9 @@ public function filterTemplateParameters(sfEvent $event, $parameters) /** * Returns the path to the last template rendered. - * + * * @param string $class Name of the rendering view class - * + * * @return string|null */ protected function getLastTemplate($class = 'sfPHPView') @@ -128,18 +128,18 @@ public function getPanelContent() $html[] = $this->renderTemplateInformation($partial['file'], $partial['parameters'], 'Partial'); } - return join("\n", $html); + return implode("\n", $html); } /** * Renders information about the passed template and its parameters. - * + * * The rendered HTML for each parameter is filtered through the "debug.web.view.filter_parameter_html" event. - * + * * @param string $file The template file path * @param array $parameters * @param string $label - * + * * @return string */ protected function renderTemplateInformation($file, $parameters, $label = 'Template') @@ -169,15 +169,15 @@ protected function renderTemplateInformation($file, $parameters, $label = 'Templ } $html[] = ''; - return join("\n", $html); + return implode("\n", $html); } /** * Formats information about a parameter as HTML. - * + * * @param string $name * @param mixed $parameter - * + * * @return string */ protected function formatParameterAsHtml($name, $parameter) @@ -192,10 +192,10 @@ protected function formatParameterAsHtml($name, $parameter) /** * Formats object information as HTML. - * + * * @param string $name * @param object $parameter - * + * * @return string */ protected function formatObjectAsHtml($name, $parameter) @@ -212,10 +212,10 @@ protected function formatObjectAsHtml($name, $parameter) /** * Formats form information as HTML. - * + * * @param string $name * @param sfForm $form - * + * * @return string */ protected function formatFormAsHtml($name, sfForm $form) @@ -242,15 +242,15 @@ protected function formatFormAsHtml($name, sfForm $form) $html[] = '
    '.$this->formatFormFieldSchemaAsHtml($form->getFormFieldSchema(), $name.'[%s]').'
'; $html[] = ''; - return join("\n", $html); + return implode("\n", $html); } /** * Formats form field schema information as HTML. - * + * * @param sfFormFieldSchema $fieldSchema * @param string $nameFormat - * + * * @return string */ protected function formatFormFieldSchemaAsHtml(sfFormFieldSchema $fieldSchema, $nameFormat = '%s') @@ -278,15 +278,15 @@ protected function formatFormFieldSchemaAsHtml(sfFormFieldSchema $fieldSchema, $ } } - return join("\n", $html); + return implode("\n", $html); } /** * Formats information about a parameter as HTML. - * + * * @param string $name * @param mixed $parameter - * + * * @return string */ protected function getParameterDescription($name, $parameter, $nameFormat = null, $typeFormat = null) @@ -306,9 +306,9 @@ protected function getParameterDescription($name, $parameter, $nameFormat = null /** * Shortens an action's template path. - * + * * @param string $path - * + * * @return string */ protected function shortenTemplatePath($path) @@ -327,9 +327,9 @@ protected function shortenTemplatePath($path) /** * Removes parameters prefixed with "sf_" from the array. - * + * * @param array $parameters - * + * * @return array */ protected function filterCoreParameters($parameters) @@ -349,9 +349,9 @@ protected function filterCoreParameters($parameters) /** * Returns a string representation of a value. - * + * * @param string $value - * + * * @return string */ protected function varExport($value) diff --git a/lib/form/sfForm.class.php b/lib/form/sfForm.class.php index fccd69d40..218b8a27b 100644 --- a/lib/form/sfForm.class.php +++ b/lib/form/sfForm.class.php @@ -848,7 +848,7 @@ public function setDefaults($defaults) if ($this->isCSRFProtected()) { - $this->setDefault(self::$CSRFFieldName, $this->getCSRFToken($this->localCSRFSecret ? $this->localCSRFSecret : self::$CSRFSecret)); + $this->setDefault(self::$CSRFFieldName, $this->getCSRFToken($this->localCSRFSecret ?: self::$CSRFSecret)); } $this->resetFormFields(); @@ -918,7 +918,7 @@ public function getCSRFToken($secret = null) { if (null === $secret) { - $secret = $this->localCSRFSecret ? $this->localCSRFSecret : self::$CSRFSecret; + $secret = $this->localCSRFSecret ?: self::$CSRFSecret; } return md5($secret.session_id().get_class($this)); diff --git a/lib/generator/sfModelGeneratorConfiguration.class.php b/lib/generator/sfModelGeneratorConfiguration.class.php index 5b2a4c3ff..0137e0f74 100644 --- a/lib/generator/sfModelGeneratorConfiguration.class.php +++ b/lib/generator/sfModelGeneratorConfiguration.class.php @@ -99,12 +99,12 @@ protected function compile() 'new' => array( 'fields' => array(), 'title' => $this->getNewTitle(), - 'actions' => $this->getNewActions() ? $this->getNewActions() : $this->getFormActions(), + 'actions' => $this->getNewActions() ?: $this->getFormActions(), ), 'edit' => array( 'fields' => array(), 'title' => $this->getEditTitle(), - 'actions' => $this->getEditActions() ? $this->getEditActions() : $this->getFormActions(), + 'actions' => $this->getEditActions() ?: $this->getFormActions(), ), ); diff --git a/lib/helper/AssetHelper.php b/lib/helper/AssetHelper.php index 8c00ef1b7..157cc8613 100644 --- a/lib/helper/AssetHelper.php +++ b/lib/helper/AssetHelper.php @@ -640,7 +640,7 @@ function _dynamic_path($uri, $format, $absolute = false) function get_javascripts_for_form(sfForm $form) { $html = ''; - foreach ($form->getJavascripts() as $file) + foreach ($form->getJavaScripts() as $file) { $html .= javascript_include_tag($file); } @@ -667,7 +667,7 @@ function use_javascripts_for_form(sfForm $form) { $response = sfContext::getInstance()->getResponse(); - foreach ($form->getJavascripts() as $file) + foreach ($form->getJavaScripts() as $file) { $response->addJavascript($file); } diff --git a/lib/helper/DateHelper.php b/lib/helper/DateHelper.php index 098a09229..564aae975 100644 --- a/lib/helper/DateHelper.php +++ b/lib/helper/DateHelper.php @@ -67,7 +67,7 @@ function format_datetime($date, $format = 'F', $culture = null, $charset = null) function distance_of_time_in_words($from_time, $to_time = null, $include_seconds = false) { - $to_time = $to_time? $to_time: time(); + $to_time = $to_time ?: time(); $distance_in_minutes = floor(abs($to_time - $from_time) / 60); $distance_in_seconds = floor(abs($to_time - $from_time)); diff --git a/lib/helper/JavascriptBaseHelper.php b/lib/helper/JavascriptBaseHelper.php index 480bd5dca..54b66d569 100644 --- a/lib/helper/JavascriptBaseHelper.php +++ b/lib/helper/JavascriptBaseHelper.php @@ -133,7 +133,7 @@ function array_or_string_for_javascript($option) { if (is_array($option)) { - return "['".join('\',\'', $option)."']"; + return "['".implode('\',\'', $option)."']"; } else if (is_string($option) && $option[0] != "'") { @@ -161,7 +161,7 @@ function options_for_javascript($options) } sort($opts); - return '{'.join(', ', $opts).'}'; + return '{'.implode(', ', $opts).'}'; } /** diff --git a/lib/helper/NumberHelper.php b/lib/helper/NumberHelper.php index 9bd427611..2f5482c90 100644 --- a/lib/helper/NumberHelper.php +++ b/lib/helper/NumberHelper.php @@ -43,5 +43,5 @@ function format_currency($amount, $currency = null, $culture = null) function _current_language($culture) { - return $culture ? $culture : sfContext::getInstance()->getUser()->getCulture(); + return $culture ?: sfContext::getInstance()->getUser()->getCulture(); } diff --git a/lib/helper/TagHelper.php b/lib/helper/TagHelper.php index ab9c2e182..b2b5e01c5 100644 --- a/lib/helper/TagHelper.php +++ b/lib/helper/TagHelper.php @@ -158,7 +158,7 @@ function _get_option(&$options, $name, $default = null) function get_id_from_name($name, $value = null) { // check to see if we have an array variable for a field name - if (strstr($name, '[')) + if (false !== strpos($name, '[')) { $name = str_replace(array('[]', '][', '[', ']'), array((($value != null) ? '_'.$value : ''), '_', '_', ''), $name); } diff --git a/lib/helper/UrlHelper.php b/lib/helper/UrlHelper.php index e510d0dfc..2c380c494 100644 --- a/lib/helper/UrlHelper.php +++ b/lib/helper/UrlHelper.php @@ -3,7 +3,7 @@ /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -109,7 +109,7 @@ function url_for1($internal_uri, $absolute = false) * echo url_for('my_module/my_action'); * => /path/to/my/action * echo url_for('@my_rule'); - * => /path/to/my/action + * => /path/to/my/action * echo url_for('@my_rule', true); * => http://myapp.example.com/path/to/my/action * @@ -136,11 +136,11 @@ function url_for() * Creates a link tag of the given name using a routed URL * based on the module/action passed as argument and the routing configuration. * It's also possible to pass a string instead of a module/action pair to - * get a link tag that just points without consideration. + * get a link tag that just points without consideration. * If null is passed as a name, the link itself will become the name. * If an object is passed as a name, the object string representation is used. - * One of the options serves for for creating javascript confirm alerts where - * if you pass 'confirm' => 'Are you sure?', the link will be guarded + * One of the options serves for for creating javascript confirm alerts where + * if you pass 'confirm' => 'Are you sure?', the link will be guarded * with a JS popup asking that question. If the user accepts, the link is processed, * otherwise not. * @@ -149,7 +149,7 @@ function url_for() * - 'query_string' - to append a query string (starting by ?) to the routed url * - 'anchor' - to append an anchor (starting by #) to the routed url * - 'confirm' - displays a javascript confirmation alert when the link is clicked - * - 'popup' - if set to true, the link opens a new browser window + * - 'popup' - if set to true, the link opens a new browser window * - 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form) * - 'method' - if set to post, delete, or put, the link submits a request with the given HTTP method instead of GET (caution: do not use inside a form) * @@ -220,14 +220,14 @@ function form_tag_for(sfForm $form, $routePrefix, $attributes = array()) * - 'query_string' - to append a query string (starting by ?) to the routed url * - 'anchor' - to append an anchor (starting by #) to the routed url * - 'confirm' - displays a javascript confirmation alert when the link is clicked - * - 'popup' - if set to true, the link opens a new browser window + * - 'popup' - if set to true, the link opens a new browser window * - 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form) * * Examples: * * echo link_to_if($user->isAdministrator(), 'Delete this page', 'my_module/my_action'); * => Delete this page - * echo link_to_if(!$user->isAdministrator(), 'Delete this page', 'my_module/my_action'); + * echo link_to_if(!$user->isAdministrator(), 'Delete this page', 'my_module/my_action'); * => Delete this page * * @@ -261,9 +261,7 @@ function link_to_if() } else { - unset($html_options['query_string']); - unset($html_options['absolute_url']); - unset($html_options['absolute']); + unset($html_options['query_string'], $html_options['absolute_url'], $html_options['absolute']); $tag = _get_option($html_options, 'tag', 'span'); @@ -283,14 +281,14 @@ function link_to_if() * - 'query_string' - to append a query string (starting by ?) to the routed url * - 'anchor' - to append an anchor (starting by #) to the routed url * - 'confirm' - displays a javascript confirmation alert when the link is clicked - * - 'popup' - if set to true, the link opens a new browser window + * - 'popup' - if set to true, the link opens a new browser window * - 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form) * * Examples: * * echo link_to_unless($user->isAdministrator(), 'Delete this page', 'my_module/my_action'); * => Delete this page - * echo link_to_unless(!$user->isAdministrator(), 'Delete this page', 'my_module/my_action'); + * echo link_to_unless(!$user->isAdministrator(), 'Delete this page', 'my_module/my_action'); * => Delete this page * * @@ -313,9 +311,9 @@ function link_to_unless() /** * Returns a URL rooted at the web root * - * @param string $path The route to append + * @param string $path The route to append * @param bool $absolute If true, an absolute path is returned (optional) - * @return The web URL root + * @return The web URL root */ function public_path($path, $absolute = false) { @@ -335,7 +333,7 @@ function public_path($path, $absolute = false) { $source = $root; } - + if (substr($path, 0, 1) != '/') { $path = '/'.$path; @@ -354,7 +352,7 @@ function public_path($path, $absolute = false) * - 'query_string' - to append a query string (starting by ?) to the routed url * - 'anchor' - to append an anchor (starting by #) to the routed url * - 'confirm' - displays a javascript confirmation alert when the button is clicked - * - 'popup' - if set to true, the button opens a new browser window + * - 'popup' - if set to true, the button opens a new browser window * - 'post' - if set to true, the button submits a POST request instead of GET (caution: do not use inside a form) * * Examples: @@ -419,7 +417,7 @@ function button_to($name, $internal_uri, $options = array()) * Returns an HTML
tag that points to a valid action, route or URL as defined by $url_for_options. * * By default, the form tag is generated in POST format, but can easily be configured along with any additional - * HTML parameters via the optional $options parameter. If you are using file uploads, be sure to set the + * HTML parameters via the optional $options parameter. If you are using file uploads, be sure to set the * multipart option to true. * * Options: @@ -633,7 +631,7 @@ function _encodeText($text) for ($i = 0; $i < strlen($text); $i++) { $char = $text{$i}; - $r = rand(0, 100); + $r = mt_rand(0, 100); # roughly 10% raw, 45% hex, 45% dec # '@' *must* be encoded. I insist. diff --git a/lib/i18n/Gettext/MO.php b/lib/i18n/Gettext/MO.php index f238904b3..6df1a4b82 100644 --- a/lib/i18n/Gettext/MO.php +++ b/lib/i18n/Gettext/MO.php @@ -16,43 +16,43 @@ /** * File::Gettext::MO - * + * * @author Michael Wallner * @license PHP License */ require_once __DIR__.'/TGettext.class.php'; -/** +/** * File_Gettext_MO - * + * * GNU MO file reader and writer. * * @author Michael Wallner * @version $Revision: 9856 $ * @access public - * @package System.I18N.core + * @package System.I18N.core */ class TGettext_MO extends TGettext { /** * file handle - * + * * @access private * @var resource */ protected $_handle = null; - + /** * big endianess - * + * * Whether to write with big endian byte order. - * + * * @access public * @var bool */ protected $writeBigEndian = false; - + /** * Constructor * @@ -60,7 +60,7 @@ class TGettext_MO extends TGettext * @return object File_Gettext_MO * @param string $file path to GNU MO file */ - function TGettext_MO($file = '') + public function __construct($file = '') { $this->file = $file; } @@ -79,7 +79,7 @@ function _read($bytes = 1) } return null; } - + /** * _readInt * @@ -93,7 +93,7 @@ function _readInt($bigendian = false) $unpacked = unpack($bigendian ? 'N' : 'V', $this->_read(4)); return array_shift($unpacked); } - + /** * _writeInt * @@ -105,7 +105,7 @@ function _writeInt($int) { return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int)); } - + /** * _write * @@ -117,7 +117,7 @@ function _write($data) { return fwrite($this->_handle, $data); } - + /** * _writeStr * @@ -129,13 +129,13 @@ function _writeStr($string) { return $this->_write($string . "\0"); } - + /** * _readStr * * @access private * @return string - * @param array $params associative array with offset and length + * @param array $params associative array with offset and length * of the string */ function _readStr($params) @@ -143,7 +143,7 @@ function _readStr($params) fseek($this->_handle, $params['offset']); return $this->_read($params['length']); } - + /** * Load MO file * @@ -156,7 +156,7 @@ function load($file = null) if (!isset($file)) { $file = $this->file; } - + // open MO file if (!is_resource($this->_handle = @fopen($file, 'rb'))) { return false; @@ -166,7 +166,7 @@ function load($file = null) @fclose($this->_handle); return false; } - + // read (part of) magic number from MO file header and define endianess //unpack returns a reference???? @@ -176,11 +176,11 @@ function load($file = null) case -34: $be = false; break; - + case -107: $be = true; break; - + default: return false; } @@ -189,15 +189,15 @@ function load($file = null) if (0 !== ($_rev = $this->_readInt($be))) { return false; } - + // count of strings in this file $count = $this->_readInt($be); - + // offset of hashing table of the msgids $offset_original = $this->_readInt($be); // offset of hashing table of the msgstrs $offset_translat = $this->_readInt($be); - + // move to msgid hash table fseek($this->_handle, $offset_original); // read lengths and offsets of msgids @@ -208,7 +208,7 @@ function load($file = null) 'offset' => $this->_readInt($be) ); } - + // move to msgstr hash table fseek($this->_handle, $offset_translat); // read lengths and offsets of msgstrs @@ -219,27 +219,27 @@ function load($file = null) 'offset' => $this->_readInt($be) ); } - + // read all for ($i = 0; $i < $count; $i++) { - $this->strings[$this->_readStr($original[$i])] = + $this->strings[$this->_readStr($original[$i])] = $this->_readStr($translat[$i]); } - + // done @flock($this->_handle, LOCK_UN); @fclose($this->_handle); $this->_handle = null; - + // check for meta info if (isset($this->strings[''])) { $this->meta = parent::meta2array($this->strings['']); unset($this->strings['']); } - + return true; } - + /** * Save MO file * @@ -252,7 +252,7 @@ function save($file = null) if (!isset($file)) { $file = $this->file; } - + // open MO file if (!is_resource($this->_handle = @fopen($file, 'wb'))) { return false; @@ -262,36 +262,36 @@ function save($file = null) @fclose($this->_handle); return false; } - + // write magic number if ($this->writeBigEndian) { $this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde)); } else { $this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95)); } - + // write file format revision $this->_writeInt(0); - + $count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0)); // write count of strings $this->_writeInt($count); - + $offset = 28; // write offset of orig. strings hash table $this->_writeInt($offset); - + $offset += ($count * 8); // write offset transl. strings hash table $this->_writeInt($offset); - + // write size of hash table (we currently ommit the hash table) $this->_writeInt(0); - + $offset += ($count * 8); // write offset of hash table $this->_writeInt($offset); - + // unshift meta info if ($meta) { $meta = ''; @@ -302,7 +302,7 @@ function save($file = null) } else { $strings = $this->strings; } - + // write offsets for original strings foreach (array_keys($strings) as $o) { $len = strlen($o); @@ -310,7 +310,7 @@ function save($file = null) $this->_writeInt($offset); $offset += $len + 1; } - + // write offsets for translated strings foreach ($strings as $t) { $len = strlen($t); @@ -328,7 +328,7 @@ function save($file = null) foreach ($strings as $t) { $this->_writeStr($t); } - + // done @flock($this->_handle, LOCK_UN); @fclose($this->_handle); diff --git a/lib/i18n/Gettext/PO.php b/lib/i18n/Gettext/PO.php index 6a6a38bd9..079828c6a 100644 --- a/lib/i18n/Gettext/PO.php +++ b/lib/i18n/Gettext/PO.php @@ -16,22 +16,22 @@ /** * File::Gettext::PO - * + * * @author Michael Wallner * @license PHP License */ - + require_once __DIR__.'/TGettext.class.php'; -/** +/** * File_Gettext_PO * * GNU PO file reader and writer. - * + * * @author Michael Wallner * @version $Revision: 9856 $ * @access public - * @package System.I18N.core + * @package System.I18N.core */ class TGettext_PO extends TGettext { @@ -42,7 +42,7 @@ class TGettext_PO extends TGettext * @return object File_Gettext_PO * @param string path to GNU PO file */ - function TGettext_PO($file = '') + public function __construct($file = '') { $this->file = $file; } @@ -59,13 +59,13 @@ function load($file = null) if (!isset($file)) { $file = $this->file; } - + // load file if (!$contents = @file($file)) { return false; } $contents = implode('', $contents); - + // match all msgid/msgstr entries $matched = preg_match_all( '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' . @@ -73,11 +73,11 @@ function load($file = null) $contents, $matches ); unset($contents); - + if (!$matched) { return false; } - + // get all msgids and msgtrs for ($i = 0; $i < $matched; $i++) { $msgid = preg_replace( @@ -86,16 +86,16 @@ function load($file = null) '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]); $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); } - + // check for meta info if (isset($this->strings[''])) { $this->meta = parent::meta2array($this->strings['']); unset($this->strings['']); } - + return true; } - + /** * Save PO file * @@ -134,7 +134,7 @@ function save($file = null) 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n" ); } - + //done @flock($fh, LOCK_UN); @fclose($fh); diff --git a/lib/i18n/Gettext/TGettext.class.php b/lib/i18n/Gettext/TGettext.class.php index fe6dc222f..4d137e538 100644 --- a/lib/i18n/Gettext/TGettext.class.php +++ b/lib/i18n/Gettext/TGettext.class.php @@ -16,7 +16,7 @@ /** * File::Gettext - * + * * @author Michael Wallner * @license PHP License */ @@ -26,11 +26,11 @@ */ //ini_set('track_errors', true); -/** +/** * File_Gettext - * + * * GNU gettext file reader and writer. - * + * * ################################################################# * # All protected members of this class are public in its childs. # * ################################################################# @@ -38,15 +38,15 @@ * @author Michael Wallner * @version $Revision: 9856 $ * @access public - * @package System.I18N.core + * @package System.I18N.core */ class TGettext { /** * strings - * + * * associative array with all [msgid => msgstr] entries - * + * * @access protected * @var array */ @@ -54,40 +54,40 @@ class TGettext /** * meta - * - * associative array containing meta + * + * associative array containing meta * information like project name or content type - * + * * @access protected * @var array */ protected $meta = array(); - + /** * file path - * + * * @access protected * @var string */ protected $file = ''; - + /** * Factory * * @static * @access public - * @return object Returns File_Gettext_PO or File_Gettext_MO on success + * @return object Returns File_Gettext_PO or File_Gettext_MO on success * or PEAR_Error on failure. * @param string $format MO or PO * @param string $file path to GNU gettext file */ static function factory($format, $file = '') { - $format = strToUpper($format); + $format = strtoupper($format); $filename = __DIR__.'/'.$format.'.php'; if (is_file($filename) == false) throw new Exception ("Class file $file not found"); - + include_once $filename; $class = 'TGettext_' . $format; @@ -99,7 +99,7 @@ static function factory($format, $file = '') * * That's a simple fake of the 'msgfmt' console command. It reads the * contents of a GNU PO file and saves them to a GNU MO file. - * + * * @static * @access public * @return mixed Returns true on success or PEAR_Error on failure. @@ -111,23 +111,23 @@ function poFile2moFile($pofile, $mofile) if (!is_file($pofile)) { throw new Exception("File $pofile doesn't exist."); } - + include_once __DIR__.'/PO.php'; - + $PO = new TGettext_PO($pofile); if (true !== ($e = $PO->load())) { return $e; } - + $MO = $PO->toMO(); if (true !== ($e = $MO->save($mofile))) { return $e; } unset($PO, $MO); - + return true; } - + /** * prepare * @@ -150,7 +150,7 @@ function prepare($string, $reverse = false) return (string) str_replace($smap, $rmap, $string); } } - + /** * meta2array * @@ -173,7 +173,7 @@ function meta2array($meta) /** * toArray - * + * * Returns meta info and strings as an array of a structure like that: * * array( @@ -190,7 +190,7 @@ function meta2array($meta) * ) * ) * - * + * * @see fromArray() * @access protected * @return array @@ -199,10 +199,10 @@ function toArray() { return array('meta' => $this->meta, 'strings' => $this->strings); } - + /** * fromArray - * + * * Assigns meta info and strings from an array of a structure like that: * * array( @@ -219,7 +219,7 @@ function toArray() * ) * ) * - * + * * @see toArray() * @access protected * @return bool @@ -239,7 +239,7 @@ function fromArray($array) } return true; } - + /** * toMO * @@ -253,7 +253,7 @@ function toMO() $MO->fromArray($this->toArray()); return $MO; } - + /** * toPO * diff --git a/lib/i18n/sfChoiceFormat.class.php b/lib/i18n/sfChoiceFormat.class.php index 4055fc113..02c4be9e7 100644 --- a/lib/i18n/sfChoiceFormat.class.php +++ b/lib/i18n/sfChoiceFormat.class.php @@ -21,18 +21,18 @@ /** * sfChoiceFormat class. - * - * sfChoiceFormat converts between ranges of numeric values and string + * + * sfChoiceFormat converts between ranges of numeric values and string * names for those ranges. * - * A sfChoiceFormat splits the real number line -Inf to +Inf into two or - * more contiguous ranges. Each range is mapped to a string. - * sfChoiceFormat is generally used in a MessageFormat for displaying + * A sfChoiceFormat splits the real number line -Inf to +Inf into two or + * more contiguous ranges. Each range is mapped to a string. + * sfChoiceFormat is generally used in a MessageFormat for displaying * grammatically correct plurals such as "There are 2 files." * * * $string = '[0] are no files |[1] is one file |(1,Inf] are {number} files'; - * + * * $formatter = new sfMessageFormat(...); //init for a source * $translated = $formatter->format($string); * @@ -45,7 +45,7 @@ * # [1,2] -- accepts values between 1 and 2, inclusive. * # (1,2) -- accepts values between 1 and 2, excluding 1 and 2. * # {1,2,3,4} -- only values defined in the set are accepted. - * # [-Inf,0) -- accepts value greater or equal to negative infinity + * # [-Inf,0) -- accepts value greater or equal to negative infinity * and strictly less than 0 * Any non-empty combinations of the delimiters of square and round brackets * are acceptable. @@ -122,13 +122,13 @@ public function isValid($number, $set) } else { - $elements[] = floatval($string); + $elements[] = (float) $string; } } $i++; } $total = count($elements); - $number = floatval($number); + $number = (float) $number; if ($leftBracket == '{' && $rightBracket == '}') { diff --git a/lib/i18n/sfDateFormat.class.php b/lib/i18n/sfDateFormat.class.php index 4cd9889bc..064bc65a1 100644 --- a/lib/i18n/sfDateFormat.class.php +++ b/lib/i18n/sfDateFormat.class.php @@ -19,17 +19,17 @@ /** * sfDateFormat class. - * - * The sfDateFormat class allows you to format dates and times with - * predefined styles in a locale-sensitive manner. Formatting times + * + * The sfDateFormat class allows you to format dates and times with + * predefined styles in a locale-sensitive manner. Formatting times * with the sfDateFormat class is similar to formatting dates. * - * Formatting dates with the sfDateFormat class is a two-step process. - * First, you create a formatter with the getDateInstance method. - * Second, you invoke the format method, which returns a string containing - * the formatted date. + * Formatting dates with the sfDateFormat class is a two-step process. + * First, you create a formatter with the getDateInstance method. + * Second, you invoke the format method, which returns a string containing + * the formatted date. * - * DateTime values are formatted using standard or custom patterns stored + * DateTime values are formatted using standard or custom patterns stored * in the properties of a DateTimeFormatInfo. * * @author Xiang Wei Zhuo @@ -41,7 +41,7 @@ class sfDateFormat { /** * A list of tokens and their function call. - * @var array + * @var array */ protected $tokens = array( 'G' => 'Era', @@ -65,13 +65,13 @@ class sfDateFormat /** * A list of methods, to be used by the token function calls. - * @var array + * @var array */ protected $methods = array(); /** * The sfDateTimeFormatInfo, containing culture specific patterns and names. - * @var sfDateTimeFormatInfo + * @var sfDateTimeFormatInfo */ protected $formatInfo; @@ -212,7 +212,7 @@ public function getDate($time, $pattern = null) * @param string $pattern the pattern * @param string $inputPattern the input pattern * @param string $charset the charset - * @return string formatted date time. + * @return string formatted date time. */ public function format($time, $pattern = 'F', $inputPattern = null, $charset = 'UTF-8') { @@ -276,7 +276,7 @@ protected function getFunctionName($token) * Gets the pattern from DateTimeFormatInfo or some predefined patterns. * If the $pattern parameter is an array of 2 element, it will assume * that the first element is the date, and second the time - * and try to find an appropriate pattern and apply + * and try to find an appropriate pattern and apply * DateTimeFormatInfo::formatDateTime * See the tutorial documentation for futher details on the patterns. * @@ -304,7 +304,7 @@ public function getPattern($pattern) break; case 'P': return $this->formatInfo->FullDatePattern; - break; + break; case 't': return $this->formatInfo->ShortTimePattern; break; @@ -371,17 +371,17 @@ public function getPattern($pattern) public function getInputPattern($pattern) { $pattern = $this->getPattern($pattern); - + $pattern = strtr($pattern, array('yyyy' => 'Y', 'h'=>'H', 'z'=>'', 'a'=>'')); $pattern = strtr($pattern, array('yy'=>'yyyy', 'Y'=>'yyyy')); - + return trim($pattern); } /** * Tokenizes the pattern. The tokens are delimited by group of * similar characters, e.g. 'aabb' will form 2 tokens of 'aa' and 'bb'. - * Any substrings, starting and ending with a single quote (') + * Any substrings, starting and ending with a single quote (') * will be treated as a single token. * * @param string $pattern pattern. @@ -427,7 +427,7 @@ protected function getTokens($pattern) return $tokens; } - + // makes a unix date from our incomplete $date array protected function getUnixDate($date) { @@ -454,7 +454,7 @@ protected function getYear($date, $pattern = 'yyyy') case 'yyy': case 'yyyy': return $year; - default: + default: throw new sfException('The pattern for year is either "y", "yy", "yyy" or "yyyy".'); } } @@ -574,7 +574,7 @@ protected function getEra($date, $pattern = 'G') } /** - * Gets the hours in 24 hour format, i.e. [0-23]. + * Gets the hours in 24 hour format, i.e. [0-23]. * "H" for non-padding, "HH" will always return 2 characters. * * @param array $date getdate format. @@ -610,11 +610,11 @@ protected function getAMPM($date, $pattern = 'a') throw new sfException('The pattern for AM/PM marker is "a".'); } - return $this->formatInfo->AMPMMarkers[intval($date['hours'] / 12)]; + return $this->formatInfo->AMPMMarkers[(int) ($date['hours'] / 12)]; } /** - * Gets the hours in 12 hour format. + * Gets the hours in 12 hour format. * "h" for non-padding, "hh" will always return 2 characters. * * @param array $date getdate format. @@ -689,7 +689,7 @@ protected function getSeconds($date, $pattern = 's') * @todo How to get the timezone for a different region? * @param array $date getdate format. * @param string $pattern a pattern. - * @return string time zone + * @return string time zone */ protected function getTimeZone($date, $pattern = 'z') { diff --git a/lib/i18n/sfMessageSource_File.class.php b/lib/i18n/sfMessageSource_File.class.php index 24c09d2bf..d40164315 100644 --- a/lib/i18n/sfMessageSource_File.class.php +++ b/lib/i18n/sfMessageSource_File.class.php @@ -159,7 +159,7 @@ public function catalogues() */ protected function getCatalogues($dir = null, $variant = null) { - $dir = $dir ? $dir : $this->getSource($variant); + $dir = $dir ?: $this->getSource($variant); $files = scandir($dir); $catalogue = array(); diff --git a/lib/i18n/sfMessageSource_MySQL.class.php b/lib/i18n/sfMessageSource_MySQL.class.php index 016951f87..a1b7b0ec3 100644 --- a/lib/i18n/sfMessageSource_MySQL.class.php +++ b/lib/i18n/sfMessageSource_MySQL.class.php @@ -20,7 +20,7 @@ /** * sfMessageSource_MySQL class. - * + * * Retrieve the message translation from a MySQL database. * * See the MessageSource::factory() method to instantiate this class. @@ -93,19 +93,19 @@ class sfMessageSource_MySQL extends sfMessageSource_Database { /** * The datasource string, full DSN to the database. - * @var string + * @var string */ protected $source; /** * The DSN array property, parsed by PEAR's DB DSN parser. - * @var array + * @var array */ protected $dsn; /** * A resource link to the database - * @var db + * @var db */ protected $db; @@ -147,7 +147,7 @@ protected function connect() } else { - $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; + $dbhost = $dsninfo['hostspec'] ?: 'localhost'; if (!empty($dsninfo['port'])) { $dbhost .= ':'.$dsninfo['port']; @@ -203,7 +203,7 @@ protected function connect() /** * Gets the database connection. * - * @return db database connection. + * @return db database connection. */ public function connection() { @@ -255,7 +255,7 @@ protected function getLastModified($source) $rs = mysql_query("SELECT date_modified FROM catalogue WHERE name = '{$source}'", $this->db); - $result = $rs ? intval(mysql_result($rs, 0)) : 0; + $result = $rs ? (int) mysql_result($rs, 0) : 0; return $result; } @@ -265,7 +265,7 @@ protected function getLastModified($source) * * @param string $variant catalogue+variant * @return boolean true if the catalogue+variant is in the database, false otherwise. - */ + */ public function isValidSource($variant) { $variant = mysql_real_escape_string ($variant, $this->db); @@ -283,7 +283,7 @@ public function isValidSource($variant) * Retrieves catalogue details, array($cat_id, $variant, $count). * * @param string $catalogue catalogue - * @return array catalogue details, array($cat_id, $variant, $count). + * @return array catalogue details, array($cat_id, $variant, $count). */ protected function getCatalogueDetails($catalogue = 'messages') { @@ -303,12 +303,12 @@ protected function getCatalogueDetails($catalogue = 'messages') return false; } - $cat_id = intval(mysql_result($rs, 0)); + $cat_id = (int) mysql_result($rs, 0); // first get the catalogue ID $rs = mysql_query("SELECT COUNT(*) FROM trans_unit WHERE cat_id = {$cat_id}", $this->db); - $count = intval(mysql_result($rs, 0)); + $count = (int) mysql_result($rs, 0); return array($cat_id, $variant, $count); } @@ -316,7 +316,7 @@ protected function getCatalogueDetails($catalogue = 'messages') /** * Updates the catalogue last modified time. * - * @return boolean true if updated, false otherwise. + * @return boolean true if updated, false otherwise. */ protected function updateCatalogueTime($cat_id, $variant) { @@ -333,7 +333,7 @@ protected function updateCatalogueTime($cat_id, $variant) } /** - * Saves the list of untranslated blocks to the translation source. + * Saves the list of untranslated blocks to the translation source. * If the translation was not found, you should add those * strings to the translation source via the append() method. * @@ -391,7 +391,7 @@ function save($catalogue = 'messages') * * @param string $message the source message to delete. * @param string $catalogue the catalogue to delete from. - * @return boolean true if deleted, false otherwise. + * @return boolean true if deleted, false otherwise. */ function delete($message, $catalogue = 'messages') { @@ -427,7 +427,7 @@ function delete($message, $catalogue = 'messages') * @param string $target the new translation string. * @param string $comments comments * @param string $catalogue the catalogue of the translation. - * @return boolean true if translation was updated, false otherwise. + * @return boolean true if translation was updated, false otherwise. */ function update($text, $target, $comments, $catalogue = 'messages') { @@ -463,7 +463,7 @@ function update($text, $target, $comments, $catalogue = 'messages') /** * Returns a list of catalogue as key and all it variants as value. * - * @return array list of catalogues + * @return array list of catalogues */ function catalogues() { diff --git a/lib/i18n/sfMessageSource_SQLite.class.php b/lib/i18n/sfMessageSource_SQLite.class.php index 6034aa3a3..e2d9bce06 100644 --- a/lib/i18n/sfMessageSource_SQLite.class.php +++ b/lib/i18n/sfMessageSource_SQLite.class.php @@ -20,7 +20,7 @@ /** * sfMessageSource_SQLite class. - * + * * Retrieve the message translation from a SQLite database. * * See the MessageSource::factory() method to instantiate this class. @@ -89,7 +89,7 @@ class sfMessageSource_SQLite extends sfMessageSource_Database { /** * The SQLite datasource, the filename of the database. - * @var string + * @var string */ protected $source; @@ -155,7 +155,7 @@ protected function getLastModified($source) $rs = sqlite_query("SELECT date_modified FROM catalogue WHERE name = '{$source}'", $db); - $result = $rs ? intval(sqlite_fetch_single($rs)) : 0; + $result = $rs ? (int) sqlite_fetch_single($rs) : 0; sqlite_close($db); @@ -173,7 +173,7 @@ public function isValidSource($variant) $variant = sqlite_escape_string($variant); $db = sqlite_open($this->source); $rs = sqlite_query("SELECT COUNT(*) FROM catalogue WHERE name = '{$variant}'", $db); - $result = $rs && intval(sqlite_fetch_single($rs)); + $result = $rs && (int) sqlite_fetch_single($rs); sqlite_close($db); return $result; @@ -205,12 +205,12 @@ protected function getCatalogueDetails($catalogue = 'messages') return false; } - $cat_id = intval(sqlite_fetch_single($rs)); + $cat_id = (int) (sqlite_fetch_single($rs); // first get the catalogue ID $rs = sqlite_query("SELECT count(msg_id) FROM trans_unit WHERE cat_id = {$cat_id}", $db); - $count = intval(sqlite_fetch_single($rs)); + $count = (int) sqlite_fetch_single($rs); sqlite_close($db); @@ -220,7 +220,7 @@ protected function getCatalogueDetails($catalogue = 'messages') /** * Updates the catalogue last modified time. * - * @return boolean true if updated, false otherwise. + * @return boolean true if updated, false otherwise. */ protected function updateCatalogueTime($cat_id, $variant, $db) { @@ -237,7 +237,7 @@ protected function updateCatalogueTime($cat_id, $variant, $db) } /** - * Saves the list of untranslated blocks to the translation source. + * Saves the list of untranslated blocks to the translation source. * If the translation was not found, you should add those * strings to the translation source via the append() method. * @@ -299,7 +299,7 @@ function save($catalogue = 'messages') * @param string $target the new translation string. * @param string $comments comments * @param string $catalogue the catalogue of the translation. - * @return boolean true if translation was updated, false otherwise. + * @return boolean true if translation was updated, false otherwise. */ function update($text, $target, $comments, $catalogue = 'messages') { @@ -343,7 +343,7 @@ function update($text, $target, $comments, $catalogue = 'messages') * * @param string $message the source message to delete. * @param string $catalogue the catalogue to delete from. - * @return boolean true if deleted, false otherwise. + * @return boolean true if deleted, false otherwise. */ function delete($message, $catalogue = 'messages') { @@ -380,7 +380,7 @@ function delete($message, $catalogue = 'messages') /** * Returns a list of catalogue as key and all it variants as value. * - * @return array list of catalogues + * @return array list of catalogues */ function catalogues() { diff --git a/lib/i18n/sfMessageSource_SQLite3.class.php b/lib/i18n/sfMessageSource_SQLite3.class.php index 35ca57528..7a639eafe 100644 --- a/lib/i18n/sfMessageSource_SQLite3.class.php +++ b/lib/i18n/sfMessageSource_SQLite3.class.php @@ -156,7 +156,7 @@ protected function getLastModified($source) $source = $db->escapeString($source); $rs = $db->querySingle("SELECT date_modified FROM catalogue WHERE name = '{$source}'"); - $result = null !== $rs ? intval($rs) : 0; + $result = null !== $rs ? (int) $rs : 0; $db->close(); @@ -175,7 +175,7 @@ public function isValidSource($variant) $variant = $db->escapeString($variant); $rs = $db->querySingle("SELECT COUNT(*) FROM catalogue WHERE name = '{$variant}'"); - $result = null !== $rs && intval($rs); + $result = null !== $rs && (int) $rs; $db->close();; @@ -208,7 +208,7 @@ protected function getCatalogueDetails($catalogue = 'messages') { if (0 == $i) { - $cat_id = intval($row[0]); + $cat_id = (int) $row[0]; } if (1 == $i) @@ -222,7 +222,7 @@ protected function getCatalogueDetails($catalogue = 'messages') // first get the catalogue ID $rs = $db->querySingle("SELECT count(msg_id) FROM trans_unit WHERE cat_id = {$cat_id}"); - $count = intval($rs); + $count = (int) $rs; $db->close(); diff --git a/lib/i18n/sfMessageSource_XLIFF.class.php b/lib/i18n/sfMessageSource_XLIFF.class.php index 40880f414..c7f3849e1 100644 --- a/lib/i18n/sfMessageSource_XLIFF.class.php +++ b/lib/i18n/sfMessageSource_XLIFF.class.php @@ -183,7 +183,7 @@ public function save($catalogue = 'messages') $lastNodes = $xpath->query('//trans-unit[not(@id <= preceding-sibling::trans-unit/@id) and not(@id <= following-sibling::trans-unit/@id)]'); if (null !== $last = $lastNodes->item(0)) { - $count = intval($last->getAttribute('id')); + $count = i(int) $last->getAttribute('id'); } else { diff --git a/lib/i18n/sfNumberFormat.class.php b/lib/i18n/sfNumberFormat.class.php index 81bcd2fb3..9c559f6f3 100644 --- a/lib/i18n/sfNumberFormat.class.php +++ b/lib/i18n/sfNumberFormat.class.php @@ -20,7 +20,7 @@ /** * sfNumberFormat class. - * + * * sfNumberFormat formats decimal numbers in any locale. The decimal * number is formatted according to a particular pattern. These * patterns can arise from the sfNumberFormatInfo object which is @@ -30,7 +30,7 @@ * * //create a invariant number formatter. * $formatter = new sfNumberFormat(); - * + * * //create a number format for the french language locale. * $fr = new sfNumberFormat('fr'); * @@ -38,7 +38,7 @@ * $format = new sfNumberFormat($numberInfo); * * - * A normal decimal number can also be displayed as a currency + * A normal decimal number can also be displayed as a currency * or as a percentage. For example * * $format->format(1234.5); //Decimal number "1234.5" @@ -50,12 +50,12 @@ * to format the number as Japanese Yen: * * $ja = new sfNumberFormat('ja_JP'); - * + * * //Japanese currency pattern, and using Japanese Yen symbol * $ja->format(123.14,'c','JPY'); //ï¿?123 (Yen 123) * * For each culture, the symbol for each currency may be different. - * + * * @author Xiang Wei Zhuo * @version v1.0, last update on Fri Dec 10 18:10:20 EST 2004 * @package symfony @@ -105,12 +105,12 @@ function __construct($formatInfo = null) * * @param mixed $number the number to format. * @param string $pattern the format pattern, either, 'c', 'd', 'e', 'p' - * or a custom pattern. E.g. "#.000" will format the number to + * or a custom pattern. E.g. "#.000" will format the number to * 3 decimal places. - * @param string $currency 3-letter ISO 4217 code. For example, the code + * @param string $currency 3-letter ISO 4217 code. For example, the code * "USD" represents the US Dollar and "EUR" represents the Euro currency. * @param string $charset The charset - * @return string formatted number string + * @return string formatted number string */ function format($number, $pattern = 'd', $currency = 'USD', $charset = 'UTF-8') { @@ -118,7 +118,7 @@ function format($number, $pattern = 'd', $currency = 'USD', $charset = 'UTF-8') if (strtolower($pattern) == 'p') { - $number = $number * 100; + $number *= 100; } // avoid conversion with exponents @@ -322,7 +322,7 @@ protected function fixFloat($float) { $string = (string) $float; - if (false === strstr($float, 'E')) + if (false === strpos($float, 'E')) { return $string; } diff --git a/lib/request/sfRequest.class.php b/lib/request/sfRequest.class.php index 98972fb99..eedfe3ebd 100644 --- a/lib/request/sfRequest.class.php +++ b/lib/request/sfRequest.class.php @@ -301,12 +301,9 @@ public function setParameter($name, $value) */ public function getContent() { - if (null === $this->content) + if (null === $this->content && '' === trim($this->content = file_get_contents('php://input'))) { - if (0 === strlen(trim($this->content = file_get_contents('php://input')))) - { - $this->content = false; - } + $this->content = false; } return $this->content; diff --git a/lib/request/sfWebRequest.class.php b/lib/request/sfWebRequest.class.php index fd56c7172..fe43a4b82 100644 --- a/lib/request/sfWebRequest.class.php +++ b/lib/request/sfWebRequest.class.php @@ -208,7 +208,7 @@ public function isAbsUri() { $pathArray = $this->getPathInfoArray(); - return isset($pathArray['REQUEST_URI']) ? preg_match('/^http/', $pathArray['REQUEST_URI']) : false; + return isset($pathArray['REQUEST_URI']) ? 0 === strpos($pathArray['REQUEST_URI'], 'http') : false; } /** @@ -465,7 +465,7 @@ public function getLanguages() $languages = $this->splitHttpAcceptHeader($_SERVER['HTTP_ACCEPT_LANGUAGE']); foreach ($languages as $lang) { - if (strstr($lang, '-')) + if (false !== strpos($lang, '-')) { $codes = explode('-', $lang); if ($codes[0] == 'i') diff --git a/lib/routing/sfPatternRouting.class.php b/lib/routing/sfPatternRouting.class.php index 2a22e1484..3479c7d61 100644 --- a/lib/routing/sfPatternRouting.class.php +++ b/lib/routing/sfPatternRouting.class.php @@ -76,7 +76,7 @@ public function initialize(sfEventDispatcher $dispatcher, sfCache $cache = null, */ public function loadConfiguration() { - if ($this->options['load_configuration'] && $config = $this->getConfigFilename()) + if ($this->options['load_configuration'] && $config = $this->getConfigFileName()) { include($config); } diff --git a/lib/service/sfServiceContainerDumperGraphviz.class.php b/lib/service/sfServiceContainerDumperGraphviz.class.php index 05f0e528c..805ec061d 100644 --- a/lib/service/sfServiceContainerDumperGraphviz.class.php +++ b/lib/service/sfServiceContainerDumperGraphviz.class.php @@ -152,7 +152,7 @@ protected function findNodes() foreach ($container->getServiceIds() as $id) { - if (in_array($id, array_keys($container->getAliases()))) + if (array_key_exists($id, $container->getAliases())) { continue; } @@ -211,7 +211,7 @@ protected function addOptions($options) protected function dotize($id) { - return strtolower(preg_replace('/[^\w]/i', '_', $id)); + return strtolower(preg_replace('/\W/i', '_', $id)); } protected function getAliases($id) diff --git a/lib/storage/sfCacheSessionStorage.class.php b/lib/storage/sfCacheSessionStorage.class.php index eeedc8e68..34fd58597 100644 --- a/lib/storage/sfCacheSessionStorage.class.php +++ b/lib/storage/sfCacheSessionStorage.class.php @@ -40,14 +40,14 @@ class sfCacheSessionStorage extends sfStorage public function initialize($options = array()) { // initialize parent - + // bc with a slightly different name formerly used here, let's be // compatible with the base class name for it from here on out if (isset($options['session_cookie_http_only'])) { $options['session_cookie_httponly'] = $options['session_cookie_http_only']; } - + parent::initialize(array_merge(array('session_name' => 'sfproject', 'session_cookie_lifetime' => '+30 days', 'session_cookie_path' => '/', @@ -102,7 +102,7 @@ public function initialize($options = array()) $ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'ua'; // generate new id based on random # / ip / user agent / secret - $this->id = md5(rand(0, 999999).$ip.$ua.$this->options['session_cookie_secret']); + $this->id = md5(mt_rand(0, 999999).$ip.$ua.$this->options['session_cookie_secret']); if(sfConfig::get('sf_logging_enabled')) { @@ -125,7 +125,7 @@ public function initialize($options = array()) // load data from cache. Watch out for the default case. We could // serialize(array()) as the default to the call but that would be a performance hit $raw = $this->cache->get($this->id, null); - if (is_null($raw)) + if (null === $raw) { $this->data = array(); } @@ -238,8 +238,8 @@ public function regenerate($destroy = false) // generate session id $ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'ua'; - - $this->id = md5(rand(0, 999999).$_SERVER['REMOTE_ADDR'].$ua.$this->options['session_cookie_secret']); + + $this->id = md5(mt_rand(0, 999999).$_SERVER['REMOTE_ADDR'].$ua.$this->options['session_cookie_secret']); // save data to cache $this->cache->set($this->id, serialize($this->data)); diff --git a/lib/storage/sfDatabaseSessionStorage.class.php b/lib/storage/sfDatabaseSessionStorage.class.php index 7798560e3..410569095 100644 --- a/lib/storage/sfDatabaseSessionStorage.class.php +++ b/lib/storage/sfDatabaseSessionStorage.class.php @@ -70,7 +70,9 @@ public function initialize($options = array()) array($this, 'sessionGC')); // start our session - session_start(); + if ('' === session_id()) { + session_start(); + } } /** @@ -102,9 +104,9 @@ public function sessionOpen($path = null, $name = null) // get the database and connection $databaseClass = get_class($database); if ($databaseClass == 'sfPropelDatabase') - { - $this->db = Propel::getConnection($database->getParameter('name')); - } + { + $this->db = Propel::getConnection($database->getParameter('name')); + } elseif($databaseClass == 'sfDoctrineDatabase') { $this->db = $database->getConnection(); diff --git a/lib/storage/sfSessionTestStorage.class.php b/lib/storage/sfSessionTestStorage.class.php index c7e2045c7..86cbd5aa2 100644 --- a/lib/storage/sfSessionTestStorage.class.php +++ b/lib/storage/sfSessionTestStorage.class.php @@ -56,7 +56,7 @@ public function initialize($options = null) } else { - $this->sessionId = md5(uniqid(rand(), true)); + $this->sessionId = md5(uniqid(mt_rand(), true)); $this->sessionData = array(); } } diff --git a/lib/task/generator/sfGenerateAppTask.class.php b/lib/task/generator/sfGenerateAppTask.class.php index e58bebc58..1abd35572 100644 --- a/lib/task/generator/sfGenerateAppTask.class.php +++ b/lib/task/generator/sfGenerateAppTask.class.php @@ -118,7 +118,7 @@ protected function execute($arguments = array(), $options = array()) if (true === $options['csrf-secret']) { - $options['csrf-secret'] = sha1(rand(111111111, 99999999).getmypid()); + $options['csrf-secret'] = sha1(mt_rand(111111111, 99999999).getmypid()); } // Set no_script_name value in settings.yml for production environment diff --git a/lib/task/help/sfListTask.class.php b/lib/task/help/sfListTask.class.php index a89b956be..c167ae807 100644 --- a/lib/task/help/sfListTask.class.php +++ b/lib/task/help/sfListTask.class.php @@ -3,7 +3,7 @@ /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -154,7 +154,7 @@ protected function outputAsXml($namespace, $tasks) $currentNamespace = $task->getNamespace(); $namespacesXML->appendChild($namespaceArrayXML[$task->getNamespace()] = $dom->createElement('namespace')); - $namespaceArrayXML[$task->getNamespace()]->setAttribute('id', $task->getNamespace() ? $task->getNamespace() : '_global'); + $namespaceArrayXML[$task->getNamespace()]->setAttribute('id', $task->getNamespace() ?: '_global'); } if (!$namespace) @@ -172,6 +172,6 @@ protected function outputAsXml($namespace, $tasks) $tasksXML->appendChild($node); } - echo $dom->saveXml(); + echo $dom->saveXML(); } } diff --git a/lib/task/plugin/sfPluginListTask.class.php b/lib/task/plugin/sfPluginListTask.class.php index c131b13d2..97a21efc4 100644 --- a/lib/task/plugin/sfPluginListTask.class.php +++ b/lib/task/plugin/sfPluginListTask.class.php @@ -3,7 +3,7 @@ /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -49,7 +49,7 @@ protected function execute($arguments = array(), $options = array()) foreach ($this->getPluginManager()->getInstalledPlugins() as $package) { $alias = $this->getPluginManager()->getEnvironment()->getRegistry()->getChannel($package->getChannel())->getAlias(); - $this->log(sprintf(' %-40s %10s-%-6s %s', $this->formatter->format($package->getPackage(), 'INFO'), $package->getVersion(), $package->getState() ? $package->getState() : null, $this->formatter->format(sprintf('# %s (%s)', $package->getChannel(), $alias), 'COMMENT'))); + $this->log(sprintf(' %-40s %10s-%-6s %s', $this->formatter->format($package->getPackage(), 'INFO'), $package->getVersion(), $package->getState() ?: null, $this->formatter->format(sprintf('# %s (%s)', $package->getChannel(), $alias), 'COMMENT'))); } } } diff --git a/lib/task/plugin/sfPluginPublishAssetsTask.class.php b/lib/task/plugin/sfPluginPublishAssetsTask.class.php index a2cfb8fdd..390f632d1 100644 --- a/lib/task/plugin/sfPluginPublishAssetsTask.class.php +++ b/lib/task/plugin/sfPluginPublishAssetsTask.class.php @@ -3,7 +3,7 @@ /* * This file is part of the symfony package. * (c) Fabien Potencier - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -32,7 +32,7 @@ protected function configure() $this->addOptions(array( new sfCommandOption('core-only', '', sfCommandOption::PARAMETER_NONE, 'If set only core plugins will publish their assets'), )); - + $this->addOptions(array( new sfCommandOption('relative', '', sfCommandOption::PARAMETER_NONE, 'If set symlinks will be relative'), )); @@ -65,7 +65,7 @@ protected function execute($arguments = array(), $options = array()) if ($diff = array_diff($arguments['plugins'], $enabledPlugins)) { - throw new InvalidArgumentException('Plugin(s) not found: '.join(', ', $diff)); + throw new InvalidArgumentException('Plugin(s) not found: '.implode(', ', $diff)); } if ($options['core-only']) diff --git a/lib/task/sfBaseTask.class.php b/lib/task/sfBaseTask.class.php index 3d300a6b0..5e0a9a212 100644 --- a/lib/task/sfBaseTask.class.php +++ b/lib/task/sfBaseTask.class.php @@ -529,19 +529,19 @@ private function convertTime($time) if ($time > 3600) { - $h = intval(abs($time / 3600)); + $h = (int) abs($time / 3600); $time -= ($h * 3600); $string .= $h. ' h '; } if ($time > 60) { - $m = intval(abs($time / 60)); + $m = (int) abs($time / 60); $time -= ($m * 60); $string .= $m. ' min '; } - $string .= intval($time).' sec'; + $string .= (int) $time.' sec'; return $string; } diff --git a/lib/task/sfFilesystem.class.php b/lib/task/sfFilesystem.class.php index 527458c9e..646f72502 100644 --- a/lib/task/sfFilesystem.class.php +++ b/lib/task/sfFilesystem.class.php @@ -65,7 +65,7 @@ public function copy($originFile, $targetFile, $options = array()) { $statTarget = stat($targetFile); $stat_origin = stat($originFile); - $mostRecent = ($stat_origin['mtime'] > $statTarget['mtime']) ? true : false; + $mostRecent = ($stat_origin['mtime'] > $statTarget['mtime']); } if ($options['override'] || !file_exists($targetFile) || $mostRecent) diff --git a/lib/task/sfTask.class.php b/lib/task/sfTask.class.php index 79de3dde5..ce14f153c 100644 --- a/lib/task/sfTask.class.php +++ b/lib/task/sfTask.class.php @@ -3,7 +3,7 @@ /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -124,7 +124,7 @@ public function run($arguments = array(), $options = array()) { if ($indexArguments[$name]->isArray()) { - $value = join(' ', (array) $value); + $value = implode(' ', (array) $value); $arguments[$pos] = isset($arguments[$pos]) ? $arguments[$pos].' '.$value : $value; } else @@ -157,7 +157,7 @@ public function run($arguments = array(), $options = array()) } // convert associative array - $value = true === $value ? $name : sprintf('%s=%s', $name, isset($indexedOptions[$name]) && $indexedOptions[$name]->isArray() ? join(' --'.$name.'=', (array) $value) : $value); + $value = true === $value ? $name : sprintf('%s=%s', $name, isset($indexedOptions[$name]) && $indexedOptions[$name]->isArray() ? implode(' --'.$name.'=', (array) $value) : $value); } // add -- before each option if needed @@ -468,7 +468,7 @@ public function ask($question, $style = 'QUESTION', $default = null) $ret = trim(fgets(STDIN)); - return $ret ? $ret : $default; + return $ret ?: $default; } /** @@ -574,7 +574,7 @@ public function asXml() $dom->formatOutput = true; $dom->appendChild($taskXML = $dom->createElement('task')); $taskXML->setAttribute('id', $this->getFullName()); - $taskXML->setAttribute('namespace', $this->getNamespace() ? $this->getNamespace() : '_global'); + $taskXML->setAttribute('namespace', $this->getNamespace() ?: '_global'); $taskXML->setAttribute('name', $this->getName()); $taskXML->appendChild($usageXML = $dom->createElement('usage')); @@ -639,7 +639,7 @@ public function asXml() } } - return $dom->saveXml(); + return $dom->saveXML(); } /** diff --git a/lib/util/sfBrowserBase.class.php b/lib/util/sfBrowserBase.class.php index d23e4727a..98a386ef1 100644 --- a/lib/util/sfBrowserBase.class.php +++ b/lib/util/sfBrowserBase.class.php @@ -60,8 +60,7 @@ public function __construct($hostname = null, $remote = null, $options = array() */ public function initialize($hostname = null, $remote = null, $options = array()) { - unset($_SERVER['argv']); - unset($_SERVER['argc']); + unset($_SERVER['argv'], $_SERVER['argc']); // setup our fake environment $this->hostname = null === $hostname ? 'localhost' : $hostname; @@ -799,7 +798,7 @@ public function doClickElement(DOMElement $item, $arguments = array(), $options { $url = $this->stack[$this->stackPosition]['uri']; } - $method = strtolower(isset($options['method']) ? $options['method'] : ($item->getAttribute('method') ? $item->getAttribute('method') : 'get')); + $method = strtolower(isset($options['method']) ? $options['method'] : ($item->getAttribute('method') ?: 'get')); // merge form default values and arguments $defaults = array(); @@ -1018,6 +1017,6 @@ public function fixUri($uri) */ protected function newSession() { - $this->defaultServerArray['session_id'] = $_SERVER['session_id'] = md5(uniqid(rand(), true)); + $this->defaultServerArray['session_id'] = $_SERVER['session_id'] = md5(uniqid(mt_rand(), true)); } } diff --git a/lib/util/sfDomCssSelector.class.php b/lib/util/sfDomCssSelector.class.php index c65c0262e..8a6d2362f 100644 --- a/lib/util/sfDomCssSelector.class.php +++ b/lib/util/sfDomCssSelector.class.php @@ -161,7 +161,7 @@ protected function getElementsForNode($selector, $root_node) // Code to deal with attribute selectors if (preg_match('/^(\w+|\*)(\[.+\])$/', $token, $matches)) { - $tagName = $matches[1] ? $matches[1] : '*'; + $tagName = $matches[1] ?: '*'; preg_match_all('/ \[ ([\w\-]+) # attribute @@ -540,7 +540,7 @@ protected function tokenize_custom_selector($selector) { throw new Exception(sprintf('Unable to parse custom selector "%s".', $selector)); } - return array('selector' => $matches[1], 'parameter' => isset($matches[3]) ? ($matches[3] ? $matches[3] : $matches[4]) : ''); + return array('selector' => $matches[1], 'parameter' => isset($matches[3]) ? ($matches[3] ?: $matches[4]) : ''); } protected function nth($cur, $result = 1, $dir = 'nextSibling') diff --git a/lib/util/sfToolkit.class.php b/lib/util/sfToolkit.class.php index a471c97ea..6c8f7b368 100644 --- a/lib/util/sfToolkit.class.php +++ b/lib/util/sfToolkit.class.php @@ -508,7 +508,7 @@ public static function getArrayValueForPath($values, $name, $default = null) */ public static function getPhpCli() { - $path = getenv('PATH') ? getenv('PATH') : getenv('Path'); + $path = getenv('PATH') ?: getenv('Path'); $suffixes = DIRECTORY_SEPARATOR == '\\' ? (getenv('PATHEXT') ? explode(PATH_SEPARATOR, getenv('PATHEXT')) : array('.exe', '.bat', '.cmd', '.com')) : array(''); foreach (array('php5', 'php') as $phpCli) { @@ -613,6 +613,6 @@ static public function addIncludePath($path, $position = 'front') throw new InvalidArgumentException(sprintf('Unrecognized position: "%s"', $position)); } - return set_include_path(join(PATH_SEPARATOR, $paths)); + return set_include_path(implode(PATH_SEPARATOR, $paths)); } } diff --git a/lib/validator/sfValidatedFile.class.php b/lib/validator/sfValidatedFile.class.php index c910d9c4c..23ea76061 100644 --- a/lib/validator/sfValidatedFile.class.php +++ b/lib/validator/sfValidatedFile.class.php @@ -131,7 +131,7 @@ public function save($file = null, $fileMode = 0666, $create = true, $dirMode = */ public function generateFilename() { - return sha1($this->getOriginalName().rand(11111, 99999)).$this->getExtension($this->getOriginalExtension()); + return sha1($this->getOriginalName().mt_rand(11111, 99999)).$this->getExtension($this->getOriginalExtension()); } /** diff --git a/lib/validator/sfValidatorBase.class.php b/lib/validator/sfValidatorBase.class.php index 2d7ac2848..831db16f9 100644 --- a/lib/validator/sfValidatorBase.class.php +++ b/lib/validator/sfValidatorBase.class.php @@ -139,7 +139,7 @@ public function addMessage($name, $value) */ public function setMessage($name, $value) { - if (!in_array($name, array_keys($this->messages))) + if (!array_key_exists($name, $this->messages)) { throw new InvalidArgumentException(sprintf('%s does not support the following error code: \'%s\'.', get_class($this), $name)); } diff --git a/lib/validator/sfValidatorDate.class.php b/lib/validator/sfValidatorDate.class.php index 7fe1a6b13..594e3b44c 100644 --- a/lib/validator/sfValidatorDate.class.php +++ b/lib/validator/sfValidatorDate.class.php @@ -71,7 +71,7 @@ protected function doClean($value) { if (!preg_match($regex, $value, $match)) { - throw new sfValidatorError($this, 'bad_format', array('value' => $value, 'date_format' => $this->getOption('date_format_error') ? $this->getOption('date_format_error') : $this->getOption('date_format'))); + throw new sfValidatorError($this, 'bad_format', array('value' => $value, 'date_format' => $this->getOption('date_format_error') ?: $this->getOption('date_format'))); } $value = $match; @@ -195,7 +195,7 @@ protected function convertDateArrayToString($value) return $this->getEmptyValue(); } - if (!checkdate(intval($value['month']), intval($value['day']), intval($value['year']))) + if (!checkdate((int) $value['month'], (int) $value['day'], (int) $value['year'])) { throw new sfValidatorError($this, 'invalid', array('value' => $value)); } @@ -215,21 +215,21 @@ protected function convertDateArrayToString($value) $clean = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", - intval($value['year']), - intval($value['month']), - intval($value['day']), - isset($value['hour']) ? intval($value['hour']) : 0, - isset($value['minute']) ? intval($value['minute']) : 0, - isset($value['second']) ? intval($value['second']) : 0 + (int) $value['year'], + (int) $value['month'], + (int) $value['day'], + isset($value['hour']) ? (int) $value['hour'] : 0, + isset($value['minute']) ? (int) $value['minute'] : 0, + isset($value['second']) ? (int) $value['second'] : 0 ); } else { $clean = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", - intval($value['year']), - intval($value['month']), - intval($value['day']), + (int) $value['year'], + (int) $value['month'], + (int) $value['day'], 0, 0, 0 diff --git a/lib/validator/sfValidatorInteger.class.php b/lib/validator/sfValidatorInteger.class.php index ab96a9092..047a49d91 100644 --- a/lib/validator/sfValidatorInteger.class.php +++ b/lib/validator/sfValidatorInteger.class.php @@ -52,9 +52,9 @@ protected function configure($options = array(), $messages = array()) */ protected function doClean($value) { - $clean = intval($value); + $clean = (int) $value; - if (strval($clean) != $value) + if ((string) $clean != $value) { throw new sfValidatorError($this, 'invalid', array('value' => $value)); } diff --git a/lib/validator/sfValidatorNumber.class.php b/lib/validator/sfValidatorNumber.class.php index 86101aaff..24150b088 100644 --- a/lib/validator/sfValidatorNumber.class.php +++ b/lib/validator/sfValidatorNumber.class.php @@ -57,7 +57,7 @@ protected function doClean($value) throw new sfValidatorError($this, 'invalid', array('value' => $value)); } - $clean = floatval($value); + $clean = (float) $value; if ($this->hasOption('max') && $clean > $this->getOption('max')) { diff --git a/lib/validator/sfValidatorTime.class.php b/lib/validator/sfValidatorTime.class.php index 7544f4ce7..5a3a70a50 100644 --- a/lib/validator/sfValidatorTime.class.php +++ b/lib/validator/sfValidatorTime.class.php @@ -59,7 +59,7 @@ protected function doClean($value) { if (!preg_match($regex, $value, $match)) { - throw new sfValidatorError($this, 'bad_format', array('value' => $value, 'time_format' => $this->getOption('time_format_error') ? $this->getOption('time_format_error') : $this->getOption('time_format'))); + throw new sfValidatorError($this, 'bad_format', array('value' => $value, 'time_format' => $this->getOption('time_format_error') ?: $this->getOption('time_format'))); } $clean = $this->convertTimeArrayToTimestamp($match); @@ -112,9 +112,9 @@ protected function convertTimeArrayToTimestamp($value) } $clean = mktime( - isset($value['hour']) ? intval($value['hour']) : 0, - isset($value['minute']) ? intval($value['minute']) : 0, - isset($value['second']) ? intval($value['second']) : 0 + isset($value['hour']) ? (int) $value['hour'] : 0, + isset($value['minute']) ? (int) $value['minute'] : 0, + isset($value['second']) ? (int) $value['second'] : 0 ); if (false === $clean) diff --git a/lib/widget/sfWidgetForm.class.php b/lib/widget/sfWidgetForm.class.php index a79968257..558ae285b 100644 --- a/lib/widget/sfWidgetForm.class.php +++ b/lib/widget/sfWidgetForm.class.php @@ -242,7 +242,7 @@ public function generateId($name, $value = null) } // check to see if we have an array variable for a field name - if (strstr($name, '[')) + if (false !== strpos($name, '[')) { $name = str_replace(array('[]', '][', '[', ']'), array((null !== $value && !is_array($value) ? '_'.$value : ''), '_', '_', ''), $name); } diff --git a/lib/widget/sfWidgetFormSchema.class.php b/lib/widget/sfWidgetFormSchema.class.php index 2c3bb832c..c660b4855 100644 --- a/lib/widget/sfWidgetFormSchema.class.php +++ b/lib/widget/sfWidgetFormSchema.class.php @@ -822,7 +822,7 @@ public function moveField($field, $action, $pivot = null) array_unshift($this->positions, $field); break; case sfWidgetFormSchema::LAST: - array_push($this->positions, $field); + $this->positions []= $field; break; case sfWidgetFormSchema::BEFORE: if (null === $pivot) diff --git a/lib/widget/sfWidgetFormSchemaFormatter.class.php b/lib/widget/sfWidgetFormSchemaFormatter.class.php index c282eccee..6a332080e 100644 --- a/lib/widget/sfWidgetFormSchemaFormatter.class.php +++ b/lib/widget/sfWidgetFormSchemaFormatter.class.php @@ -245,7 +245,7 @@ protected function unnestErrors($errors, $prefix = '') $err = $this->translate($error); } - if (!is_integer($name)) + if (!is_int($name)) { $newErrors[] = strtr($this->getNamedErrorRowFormatInARow(), array('%error%' => $err, '%name%' => ($prefix ? $prefix.' > ' : '').$name)); } diff --git a/lib/widget/sfWidgetFormSelect.class.php b/lib/widget/sfWidgetFormSelect.class.php index ccf8fe519..34f4438b8 100644 --- a/lib/widget/sfWidgetFormSelect.class.php +++ b/lib/widget/sfWidgetFormSelect.class.php @@ -88,7 +88,7 @@ protected function getOptionsForSelect($value, $choices) $value_set = array(); foreach ($value as $v) { - $value_set[strval($v)] = true; + $value_set[(string) $v] = true; } $options = array(); @@ -101,7 +101,7 @@ protected function getOptionsForSelect($value, $choices) else { $attributes = array('value' => self::escapeOnce($key)); - if (isset($value_set[strval($key)])) + if (isset($value_set[(string) $key])) { $attributes['selected'] = 'selected'; } diff --git a/lib/widget/sfWidgetFormSelectCheckbox.class.php b/lib/widget/sfWidgetFormSelectCheckbox.class.php index 864781b54..336058335 100644 --- a/lib/widget/sfWidgetFormSelectCheckbox.class.php +++ b/lib/widget/sfWidgetFormSelectCheckbox.class.php @@ -102,7 +102,7 @@ protected function formatChoices($name, $value, $choices, $attributes) 'id' => $id = $this->generateId($name, self::escapeOnce($key)), ); - if ((is_array($value) && in_array(strval($key), $value)) || (is_string($value) && strval($key) == strval($value))) + if ((is_array($value) && in_array((string) $key, $value)) || (is_string($value) && (string) $key == (string) $value)) { $baseAttributes['checked'] = 'checked'; } diff --git a/lib/widget/sfWidgetFormSelectRadio.class.php b/lib/widget/sfWidgetFormSelectRadio.class.php index 5bcc83a7a..aae552db3 100644 --- a/lib/widget/sfWidgetFormSelectRadio.class.php +++ b/lib/widget/sfWidgetFormSelectRadio.class.php @@ -97,7 +97,7 @@ protected function formatChoices($name, $value, $choices, $attributes) 'id' => $id = $this->generateId($name, self::escapeOnce($key)), ); - if (strval($key) == strval($value === false ? 0 : $value)) + if ((string) $key == (string) ($value === false ? 0 : $value)) { $baseAttributes['checked'] = 'checked'; } diff --git a/lib/yaml/sfYamlInline.class.php b/lib/yaml/sfYamlInline.class.php index 598981320..1c391bdd6 100644 --- a/lib/yaml/sfYamlInline.class.php +++ b/lib/yaml/sfYamlInline.class.php @@ -31,7 +31,7 @@ static public function load($value) { $value = trim($value); - if (0 == strlen($value)) + if ('' === $value) { return ''; } @@ -100,7 +100,7 @@ static public function dump($value) case ctype_digit($value): return is_string($value) ? "'$value'" : (int) $value; case is_numeric($value): - return is_infinite($value) ? str_ireplace('INF', '.Inf', strval($value)) : (is_string($value) ? "'$value'" : $value); + return is_infinite($value) ? str_ireplace('INF', '.Inf', (string) $value) : (is_string($value) ? "'$value'" : $value); case false !== strpos($value, "\n") || false !== strpos($value, "\r"): return sprintf('"%s"', str_replace(array('"', "\n", "\r"), array('\\"', '\n', '\r'), $value)); case preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ - ? | < > = ! % @ ` ]/x', $value): @@ -248,7 +248,7 @@ static protected function parseSequence($sequence, &$i = 0) { $output = array(); $len = strlen($sequence); - $i += 1; + ++$i; // [foo, bar, ...] while ($i < $len) @@ -308,7 +308,7 @@ static protected function parseMapping($mapping, &$i = 0) { $output = array(); $len = strlen($mapping); - $i += 1; + ++$i; // {foo: bar, bar:foo, ...} while ($i < $len) @@ -394,26 +394,26 @@ static protected function evaluateScalar($scalar) case 0 === strpos($scalar, '!str'): return (string) substr($scalar, 5); case 0 === strpos($scalar, '! '): - return intval(self::parseScalar(substr($scalar, 2))); + return (int) self::parseScalar(substr($scalar, 2)); case 0 === strpos($scalar, '!!php/object:'): return unserialize(substr($scalar, 13)); case ctype_digit($scalar): $raw = $scalar; - $cast = intval($scalar); + $cast = (int) $scalar; return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw); case in_array(strtolower($scalar), $trueValues): return true; case in_array(strtolower($scalar), $falseValues): return false; case is_numeric($scalar): - return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar); + return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : (float) $scalar; case 0 == strcasecmp($scalar, '.inf'): case 0 == strcasecmp($scalar, '.NaN'): return -log(0); case 0 == strcasecmp($scalar, '-.inf'): return log(0); - case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar): - return floatval(str_replace(',', '', $scalar)); + case preg_match('/^(-|\+)?[0-9,]+(\.\d+)?$/', $scalar): + return (float) str_replace(',', '', $scalar); case preg_match(self::getTimestampRegex(), $scalar): return strtotime($scalar); default: diff --git a/lib/yaml/sfYamlParser.class.php b/lib/yaml/sfYamlParser.class.php index 7cd5ae91a..69b9f2651 100644 --- a/lib/yaml/sfYamlParser.class.php +++ b/lib/yaml/sfYamlParser.class.php @@ -421,7 +421,7 @@ protected function parseValue($value) { $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : ''; - return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), intval(abs($modifiers))); + return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers)); } else { From c6565415df037fcfb4bdcf9c7ffa5a4e6879e18c Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sat, 18 Jul 2015 18:47:11 +0200 Subject: [PATCH 2/5] Php Inspections (EA Extended): dropped senseless proxy function --- lib/storage/sfDatabaseSessionStorage.class.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/storage/sfDatabaseSessionStorage.class.php b/lib/storage/sfDatabaseSessionStorage.class.php index 410569095..db60035bd 100644 --- a/lib/storage/sfDatabaseSessionStorage.class.php +++ b/lib/storage/sfDatabaseSessionStorage.class.php @@ -195,13 +195,4 @@ public function regenerate($destroy = false) return $this->sessionWrite($newId, $this->sessionRead($currentId)); } - - /** - * Executes the shutdown procedure. - * - */ - public function shutdown() - { - parent::shutdown(); - } } From dc7b44bd2e35eb01cd4941f6348daa5883dfa22d Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sat, 18 Jul 2015 18:53:13 +0200 Subject: [PATCH 3/5] Php Inspections (EA Extended): revert session class changes --- lib/storage/sfDatabaseSessionStorage.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/storage/sfDatabaseSessionStorage.class.php b/lib/storage/sfDatabaseSessionStorage.class.php index db60035bd..4e3362b55 100644 --- a/lib/storage/sfDatabaseSessionStorage.class.php +++ b/lib/storage/sfDatabaseSessionStorage.class.php @@ -70,9 +70,7 @@ public function initialize($options = array()) array($this, 'sessionGC')); // start our session - if ('' === session_id()) { - session_start(); - } + session_start(); } /** From 3a047e14ad65f9647e48ce2a7e762d5acca283ec Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sat, 18 Jul 2015 18:57:40 +0200 Subject: [PATCH 4/5] Php Inspections (EA Extended): syntax fix --- lib/i18n/sfMessageSource_XLIFF.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/sfMessageSource_XLIFF.class.php b/lib/i18n/sfMessageSource_XLIFF.class.php index c7f3849e1..01dda3b7f 100644 --- a/lib/i18n/sfMessageSource_XLIFF.class.php +++ b/lib/i18n/sfMessageSource_XLIFF.class.php @@ -183,7 +183,7 @@ public function save($catalogue = 'messages') $lastNodes = $xpath->query('//trans-unit[not(@id <= preceding-sibling::trans-unit/@id) and not(@id <= following-sibling::trans-unit/@id)]'); if (null !== $last = $lastNodes->item(0)) { - $count = i(int) $last->getAttribute('id'); + $count = (int) $last->getAttribute('id'); } else { From b484e80a775d8a35eb56f846e2909aac64a82f8b Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sat, 18 Jul 2015 19:19:27 +0200 Subject: [PATCH 5/5] Php Inspections (EA Extended): UTs SCA --- test/unit/command/sfCommandArgumentTest.php | 2 +- test/unit/command/sfCommandOptionTest.php | 4 ++-- test/unit/request/sfWebRequestTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/command/sfCommandArgumentTest.php b/test/unit/command/sfCommandArgumentTest.php index 18495e8f6..892f4b776 100644 --- a/test/unit/command/sfCommandArgumentTest.php +++ b/test/unit/command/sfCommandArgumentTest.php @@ -63,7 +63,7 @@ $t->diag('->setDefault()'); $argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL, '', 'default'); $argument->setDefault(null); -$t->ok(is_null($argument->getDefault()), '->setDefault() can reset the default value by passing null'); +$t->ok(null === $argument->getDefault(), '->setDefault() can reset the default value by passing null'); $argument->setDefault('another'); $t->is($argument->getDefault(), 'another', '->setDefault() changes the default value'); diff --git a/test/unit/command/sfCommandOptionTest.php b/test/unit/command/sfCommandOptionTest.php index 4f0504f06..c9cb32d9e 100644 --- a/test/unit/command/sfCommandOptionTest.php +++ b/test/unit/command/sfCommandOptionTest.php @@ -84,7 +84,7 @@ $t->is($option->getDefault(), 'default', '->getDefault() returns the default value'); $option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_REQUIRED); -$t->ok(is_null($option->getDefault()), '->getDefault() returns null if no default value is configured'); +$t->ok(null === $option->getDefault(), '->getDefault() returns null if no default value is configured'); $option = new sfCommandOption('foo', null, sfCommandOption::IS_ARRAY); $t->is($option->getDefault(), array(), '->getDefault() returns an empty array if option is an array'); @@ -96,7 +96,7 @@ $t->diag('->setDefault()'); $option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_REQUIRED, '', 'default'); $option->setDefault(null); -$t->ok(is_null($option->getDefault()), '->setDefault() can reset the default value by passing null'); +$t->ok(null === $option->getDefault(), '->setDefault() can reset the default value by passing null'); $option->setDefault('another'); $t->is($option->getDefault(), 'another', '->setDefault() changes the default value'); diff --git a/test/unit/request/sfWebRequestTest.php b/test/unit/request/sfWebRequestTest.php index de2a38529..5af4a4e23 100644 --- a/test/unit/request/sfWebRequestTest.php +++ b/test/unit/request/sfWebRequestTest.php @@ -137,7 +137,7 @@ public function resetPathInfoArray() // ->getRequestFormat() ->setRequestFormat() $t->diag('->getRequestFormat() ->setRequestFormat()'); -$t->ok(is_null($request->getRequestFormat()), '->getRequestFormat() returns null if the format is not defined in the request'); +$t->ok(null === $request->getRequestFormat(), '->getRequestFormat() returns null if the format is not defined in the request'); $request->setParameter('sf_format', 'js'); $t->is($request->getRequestFormat(), 'js', '->getRequestFormat() returns the request format');