Commit a565fb37 authored by Cédric Anne's avatar Cédric Anne Committed by Johan Cwiklinski
Browse files

Apply namespace/use directives coding rules

parent c8eb4745
......@@ -37,7 +37,7 @@ Html::header_nocache();
try {
$ma = new MassiveAction($_POST, $_GET, 'specialize');
} catch (Exception $e) {
} catch (\Exception $e) {
echo "<div class='center'><img src='".$CFG_GLPI["root_doc"]."/pics/warning.png' alt='".
__s('Warning')."'><br><br>";
echo "<span class='b'>".$e->getMessage()."</span><br>";
......
......@@ -43,7 +43,7 @@ Session::checkLoginUser();
try {
$ma = new MassiveAction($_POST, $_GET, 'initial');
} catch (Exception $e) {
} catch (\Exception $e) {
echo "<div class='center'><img src='".$CFG_GLPI["root_doc"]."/pics/warning.png' alt='".
__s('Warning')."'><br><br>";
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b0a619b67a42b0ed750e2c683e459560",
"content-hash": "9c05bd5d6f1d5359a301ba1268279d0c",
"packages": [
{
"name": "blueimp/jquery-file-upload",
......@@ -3922,20 +3922,21 @@
},
{
"name": "glpi-project/coding-standard",
"version": "0.7.2",
"version": "0.8",
"source": {
"type": "git",
"url": "https://github.com/glpi-project/coding-standard.git",
"reference": "dbba6566e1ce7f7d0778794cd6e93bc07080c8c7"
"reference": "a34ec2abf52e720ef700f59a91a4dde963b9f33e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/glpi-project/coding-standard/zipball/dbba6566e1ce7f7d0778794cd6e93bc07080c8c7",
"reference": "dbba6566e1ce7f7d0778794cd6e93bc07080c8c7",
"url": "https://api.github.com/repos/glpi-project/coding-standard/zipball/a34ec2abf52e720ef700f59a91a4dde963b9f33e",
"reference": "a34ec2abf52e720ef700f59a91a4dde963b9f33e",
"shasum": ""
},
"require": {
"squizlabs/php_codesniffer": "^3.5"
"slevomat/coding-standard": "^6.3",
"squizlabs/php_codesniffer": "^3.5.5"
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
......@@ -3955,7 +3956,7 @@
"glpi",
"phpcs"
],
"time": "2019-10-31T10:30:33+00:00"
"time": "2020-06-03T08:54:27+00:00"
},
{
"name": "grasmash/expander",
......@@ -4550,6 +4551,55 @@
],
"time": "2020-06-07T10:40:07+00:00"
},
{
"name": "phpstan/phpdoc-parser",
"version": "0.4.4",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "d8d9d4645379e677466d407034436bb155b11c65"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/d8d9d4645379e677466d407034436bb155b11c65",
"reference": "d8d9d4645379e677466d407034436bb155b11c65",
"shasum": ""
},
"require": {
"php": "~7.1"
},
"require-dev": {
"consistence/coding-standard": "^3.5",
"ergebnis/composer-normalize": "^2.0.2",
"jakub-onderka/php-parallel-lint": "^0.9.2",
"phing/phing": "^2.16.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.19",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^6.3",
"slevomat/coding-standard": "^4.7.2",
"symfony/process": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.4-dev"
}
},
"autoload": {
"psr-4": {
"PHPStan\\PhpDocParser\\": [
"src/"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"time": "2020-04-13T16:28:46+00:00"
},
{
"name": "scrutinizer/ocular",
"version": "1.6.0",
......@@ -4639,18 +4689,75 @@
"description": "A security checker for your composer.lock",
"time": "2019-11-01T13:20:14+00:00"
},
{
"name": "slevomat/coding-standard",
"version": "6.3.8",
"source": {
"type": "git",
"url": "https://github.com/slevomat/coding-standard.git",
"reference": "500f55b5e2dee1dcef8e88f2038990acdba29f1c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/slevomat/coding-standard/zipball/500f55b5e2dee1dcef8e88f2038990acdba29f1c",
"reference": "500f55b5e2dee1dcef8e88f2038990acdba29f1c",
"shasum": ""
},
"require": {
"php": "^7.1",
"phpstan/phpdoc-parser": "0.4.0 - 0.4.4",
"squizlabs/php_codesniffer": "^3.5.5"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "0.6.2",
"phing/phing": "2.16.3",
"php-parallel-lint/php-parallel-lint": "1.2.0",
"phpstan/phpstan": "0.12.19",
"phpstan/phpstan-deprecation-rules": "0.12.2",
"phpstan/phpstan-phpunit": "0.12.8",
"phpstan/phpstan-strict-rules": "0.12.2",
"phpunit/phpunit": "7.5.20|8.5.2|9.1.2"
},
"type": "phpcodesniffer-standard",
"extra": {
"branch-alias": {
"dev-master": "6.x-dev"
}
},
"autoload": {
"psr-4": {
"SlevomatCodingStandard\\": "SlevomatCodingStandard"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.",
"funding": [
{
"url": "https://github.com/kukulich",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard",
"type": "tidelift"
}
],
"time": "2020-05-27T06:28:47+00:00"
},
{
"name": "squizlabs/php_codesniffer",
"version": "3.5.3",
"version": "3.5.5",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "557a1fc7ac702c66b0bbfe16ab3d55839ef724cb"
"reference": "73e2e7f57d958e7228fce50dc0c61f58f017f9f6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/557a1fc7ac702c66b0bbfe16ab3d55839ef724cb",
"reference": "557a1fc7ac702c66b0bbfe16ab3d55839ef724cb",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/73e2e7f57d958e7228fce50dc0c61f58f017f9f6",
"reference": "73e2e7f57d958e7228fce50dc0c61f58f017f9f6",
"shasum": ""
},
"require": {
......@@ -4688,7 +4795,7 @@
"phpcs",
"standards"
],
"time": "2019-12-04T04:46:47+00:00"
"time": "2020-04-17T01:09:41+00:00"
},
{
"name": "symfony/event-dispatcher",
......@@ -4758,20 +4865,6 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-05-20T08:37:50+00:00"
},
{
......@@ -4880,20 +4973,6 @@
],
"description": "Symfony Filesystem Component",
"homepage": "https://symfony.com",
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-05-30T18:50:54+00:00"
},
{
......@@ -5266,20 +5345,6 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-05-20T08:37:50+00:00"
}
],
......
......@@ -41,7 +41,7 @@ Html::header_nocache();
try {
$ma = new MassiveAction($_POST, $_GET, 'process');
} catch (Exception $e) {
} catch (\Exception $e) {
Html::popHeader(__('Bulk modification error'), $_SERVER['PHP_SELF']);
echo "<div class='center'><img src='".$CFG_GLPI["root_doc"]."/pics/warning.png' alt='".
......
......@@ -30,7 +30,6 @@
* ---------------------------------------------------------------------
*/
use Glpi\Event;
include ('../inc/includes.php');
......
......@@ -32,7 +32,6 @@
include ('../inc/includes.php');
use Glpi\Exception\PasswordTooWeakException;
Session::checkLoginUser();
......@@ -77,7 +76,7 @@ if (array_key_exists('update', $_POST)) {
} else {
$error_messages = [__('An error occured during password update')];
}
} catch (PasswordTooWeakException $exception) {
} catch (\Glpi\Exception\PasswordTooWeakException $exception) {
$error_messages = $exception->getMessages();
}
}
......
......@@ -46,8 +46,6 @@ use Config;
use Contract;
use Document;
use Dropdown;
use Glpi\Exception\ForgetPasswordException;
use Glpi\Exception\PasswordTooWeakException;
use Html;
use Infocom;
use Item_Devices;
......@@ -2168,7 +2166,7 @@ abstract class API extends CommonGLPI {
$email = Toolbox::addslashes_deep($params['email']);
try {
$user->forgetPassword($email);
} catch (ForgetPasswordException $e) {
} catch (\Glpi\Exception\ForgetPasswordException $e) {
return $this->returnError($e->getMessage());
}
return $this->returnResponse([
......@@ -2185,9 +2183,9 @@ abstract class API extends CommonGLPI {
try {
$user->updateForgottenPassword($input);
return $this->returnResponse([__("Reset password successful.")]);
} catch (ForgetPasswordException $e) {
} catch (\Glpi\Exception\ForgetPasswordException $e) {
return $this->returnError($e->getMessage());
} catch (PasswordTooWeakException $e) {
} catch (\Glpi\Exception\PasswordTooWeakException $e) {
implode('\n', $e->getMessages());
return $this->returnError(implode('\n', $e->getMessages()));
}
......
......@@ -36,9 +36,9 @@ if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
use Psr\SimpleCache\CacheInterface;
use Laminas\Cache\Psr\SimpleCache\SimpleCacheDecorator;
use Laminas\Cache\Storage\StorageInterface;
use Psr\SimpleCache\CacheInterface;
class SimpleCache extends SimpleCacheDecorator implements CacheInterface {
......
......@@ -38,7 +38,7 @@ if (!defined('GLPI_ROOT')) {
/**
* @since 0.84
**/
class CommonDBConnexityItemNotFound extends Exception {
class CommonDBConnexityItemNotFound extends \Exception {
}
......
......@@ -235,12 +235,12 @@ class CommonDBTM extends CommonGLPI {
static function getTableField($field, $classname = null) {
if (empty($field)) {
throw new InvalidArgumentException('Argument $field cannot be empty.');
throw new \InvalidArgumentException('Argument $field cannot be empty.');
}
$tablename = self::getTable($classname);
if (empty($tablename)) {
throw new LogicException('Invalid table name.');
throw new \LogicException('Invalid table name.');
}
return sprintf('%s.%s', $tablename, $field);
......
......@@ -8140,7 +8140,7 @@ abstract class CommonITILObject extends CommonDBTM {
} else if (isset($this->fields['status'])) {
$status = $this->fields['status'];
} else {
throw new LogicException("Can't get status value: no object loaded");
throw new \LogicException("Can't get status value: no object loaded");
}
return $status == CommonITILObject::INCOMING;
......
......@@ -2110,7 +2110,7 @@ abstract class CommonITILTask extends CommonDBTM implements CalDAVCompatibleItem
$vtodo = $vcalendar->getBaseComponent();
if (null !== $vtodo->RRULE) {
throw new UnexpectedValueException('RRULE not yet implemented for ITIL tasks');
throw new \UnexpectedValueException('RRULE not yet implemented for ITIL tasks');
}
$input = $this->getCommonInputFromVcomponent($vtodo);
......
......@@ -30,8 +30,8 @@
* ---------------------------------------------------------------------
*/
use Glpi\Dashboard\Grid;
use Glpi\Cache\SimpleCache;
use Glpi\Dashboard\Grid;
use Glpi\Exception\PasswordTooWeakException;
use Glpi\System\RequirementsManager;
use Laminas\Cache\Storage\AvailableSpaceCapableInterface;
......@@ -1558,7 +1558,7 @@ class Config extends CommonDBTM {
global $CFG_GLPI;
$ok = true;
$exception = new PasswordTooWeakException();
$exception = new \Glpi\Exception\PasswordTooWeakException();
if ($CFG_GLPI["use_password_security"]) {
if (Toolbox::strlen($password) < $CFG_GLPI['password_min_length']) {
$ok = false;
......@@ -3259,7 +3259,7 @@ class Config extends CommonDBTM {
// Create adapter
try {
$storage = Laminas\Cache\StorageFactory::factory($opt);
} catch (Exception $e) {
} catch (\Exception $e) {
if (!$is_computed_config) {
Toolbox::logError($e->getMessage());
}
......@@ -3282,7 +3282,7 @@ class Config extends CommonDBTM {
try {
$storage = Laminas\Cache\StorageFactory::factory($opt);
$fallback = true;
} catch (Exception $e1) {
} catch (\Exception $e1) {
Toolbox::logError($e1->getMessage());
if (isset($_SESSION['glpi_use_mode'])
&& Session::DEBUG_MODE == $_SESSION['glpi_use_mode']) {
......
......@@ -37,7 +37,6 @@ if (!defined('GLPI_ROOT')) {
}
use DB;
use Glpi\Console\Command\GlpiCommandInterface;
use Glpi\System\RequirementsManager;
use Symfony\Component\Console\Command\Command;
......@@ -90,7 +89,7 @@ abstract class AbstractCommand extends Command implements GlpiCommandInterface {
global $DB;
if ($this->requires_db && (!($DB instanceof DB) || !$DB->connected)) {
throw new RuntimeException(__('Unable to connect to database.'));
throw new \Symfony\Component\Console\Exception\RuntimeException(__('Unable to connect to database.'));
}
$this->db = $DB;
......
......@@ -45,19 +45,17 @@ use Glpi\Console\Command\GlpiCommandInterface;
use Glpi\System\RequirementsManager;
use Plugin;
use Session;
use Toolbox;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Output\OutputInterface;
use Toolbox;
class Application extends BaseApplication {
......@@ -201,7 +199,7 @@ class Application extends BaseApplication {
// Trigger error on invalid lang. This is not done before as error handler would not be set.
$lang = $input->getParameterOption('--lang', null, true);
if (null !== $lang && !array_key_exists($lang, $CFG_GLPI['languages'])) {
throw new RuntimeException(
throw new \Symfony\Component\Console\Exception\RuntimeException(
sprintf(__('Invalid "--lang" option value "%s".'), $lang)
);
}
......@@ -304,7 +302,7 @@ class Application extends BaseApplication {
$checkdb = Config::displayCheckDbEngine();
$message = ob_get_clean();
if ($checkdb > 0) {
throw new RuntimeException($message);
throw new \Symfony\Component\Console\Exception\RuntimeException($message);
}
}
......@@ -319,7 +317,7 @@ class Application extends BaseApplication {
private function initSession() {
if (!is_writable(GLPI_SESSION_DIR)) {
throw new RuntimeException(
throw new \Symfony\Component\Console\Exception\RuntimeException(
sprintf(__('Cannot write in "%s" directory.'), GLPI_SESSION_DIR)
);
}
......@@ -439,7 +437,7 @@ class Application extends BaseApplication {
if ($command instanceof ForceNoPluginsOptionCommandInterface) {
return !$command->getNoPluginsOptionValue();
}
} catch (CommandNotFoundException $e) {
} catch (\Symfony\Component\Console\Exception\CommandNotFoundException $e) {
// Command will not be found at this point if it is a plugin command
$command = null; // Say hello to CS checker
}
......
......@@ -41,10 +41,8 @@ use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ReflectionClass;
use SplFileInfo;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
use Symfony\Component\Console\Exception\CommandNotFoundException;
/**
* Core and plugins command loader.
......@@ -83,7 +81,7 @@ class CommandLoader implements CommandLoaderInterface {
public function get($name) {
if (!array_key_exists($name, $this->commands)) {
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
throw new \Symfony\Component\Console\Exception\CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
}
return $this->commands[$name];
......
......@@ -40,7 +40,6 @@ use Config;
use DBConnection;
use Glpi\Console\AbstractCommand;
use Glpi\Console\Command\ForceNoPluginsOptionCommandInterface;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
......@@ -292,20 +291,20 @@ abstract class AbstractConfigureCommand extends AbstractCommand implements Force
$db_pass = $input->getOption('db-password');
if (empty($db_name)) {
throw new InvalidArgumentException(
throw new \Symfony\Component\Console\Exception\InvalidArgumentException(
__('Database name defined by --db-name option cannot be empty.')
);
}
if (empty($db_user)) {
throw new InvalidArgumentException(
throw new \Symfony\Component\Console\Exception\InvalidArgumentException(
__('Database user defined by --db-user option cannot be empty.')
);
}
if (null === $db_pass) {
// Will be null if option used without value and without interaction
throw new InvalidArgumentException(
throw new \Symfony\Component\Console\Exception\InvalidArgumentException(
__('--db-password option value cannot be null.')
);
}
......
......@@ -37,10 +37,9 @@ if (!defined('GLPI_ROOT')) {
}
use Glpi\Console\AbstractCommand;
use SebastianBergmann\Diff\Differ;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use SebastianBergmann\Diff\Differ;
class CheckCommand extends AbstractCommand {
......
......@@ -38,13 +38,11 @@ if (!defined('GLPI_ROOT')) {
use DB;
use GLPIKey;
use Toolbox;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Toolbox;
class InstallCommand extends AbstractConfigureCommand {
......@@ -253,7 +251,7 @@ class InstallCommand extends AbstractConfigureCommand {
AND table_name LIKE 'glpi_%'"
);
if (!$tables_result) {
throw new RuntimeException('Unable to check GLPI tables existence.');
throw new \Symfony\Component\Console\Exception\RuntimeException('Unable to check GLPI tables existence.');
}
if ($tables_result->fetch_array()[0] > 0 && !$force) {
$output->writeln(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment