Ver Fonte

Added GLPI coding standards

Edgard há 6 anos atrás
pai
commit
81f9b898bb
9 ficheiros alterados com 172 adições e 61 exclusões
  1. 18 0
      .phpcs.xml
  2. 5 0
      composer.json
  3. 92 3
      composer.lock
  4. 10 10
      front/callback.php
  5. 2 2
      front/provider.form.php
  6. 1 1
      front/provider.php
  7. 12 13
      hook.php
  8. 30 30
      inc/provider.class.php
  9. 2 2
      setup.php

+ 18 - 0
.phpcs.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<ruleset>
+
+   <!-- rules -->
+   <rule ref="./vendor/glpi-project/coding-standard/GlpiStandard">
+      <exclude name="Generic.Arrays.DisallowLongArraySyntax" />
+   </rule>
+   <!-- keep support for php 5.3 -->
+   <rule ref="Generic.Arrays.DisallowShortArraySyntax" />
+
+   <!-- files -->
+   <file>.</file>
+   <exclude-pattern>vendor</exclude-pattern>
+
+   <!-- args -->
+   <arg name="extensions" value="php,php5,inc"/>
+   <arg name="encoding" value="UTF-8"/>
+</ruleset>

+ 5 - 0
composer.json

@@ -1,4 +1,6 @@
 {
+    "name": "edgardmessias/glpi-singlesignon",
+    "description": "",
     "require": {
         "league/oauth2-client": "^2.2",
         "league/oauth2-facebook": "^2.0",
@@ -7,6 +9,9 @@
         "league/oauth2-instagram": "^2.0",
         "league/oauth2-linkedin": "^2.0"
     },
+    "require-dev": {
+        "glpi-project/coding-standard": "^0.7.1"
+    },
     "config": {
         "platform": {
             "php": "5.6"

+ 92 - 3
composer.lock

@@ -1,10 +1,10 @@
 {
     "_readme": [
         "This file locks the dependencies of your project to a known state",
-        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "b586139b80f70524bf5995e6e42dd7c4",
+    "content-hash": "3a53533eee9889bd65c4176f5e0c5bbb",
     "packages": [
         {
             "name": "eloquent/phony",
@@ -721,7 +721,96 @@
             "time": "2016-08-06T14:39:51+00:00"
         }
     ],
-    "packages-dev": [],
+    "packages-dev": [
+        {
+            "name": "glpi-project/coding-standard",
+            "version": "0.7.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/glpi-project/coding-standard.git",
+                "reference": "1cef37d764aecf8fd7d5d167db25da97e289cb03"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/glpi-project/coding-standard/zipball/1cef37d764aecf8fd7d5d167db25da97e289cb03",
+                "reference": "1cef37d764aecf8fd7d5d167db25da97e289cb03",
+                "shasum": ""
+            },
+            "require": {
+                "squizlabs/php_codesniffer": "^3.3"
+            },
+            "type": "library",
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "GPL-2.0-or-later"
+            ],
+            "authors": [
+                {
+                    "name": "Teclib'",
+                    "email": "glpi@teclib.com",
+                    "homepage": "https://teclib.com"
+                }
+            ],
+            "description": "GLPI PHP CodeSniffer Coding Standard",
+            "keywords": [
+                "codesniffer",
+                "glpi",
+                "phpcs"
+            ],
+            "time": "2018-06-07T08:45:05+00:00"
+        },
+        {
+            "name": "squizlabs/php_codesniffer",
+            "version": "3.4.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
+                "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8",
+                "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8",
+                "shasum": ""
+            },
+            "require": {
+                "ext-simplexml": "*",
+                "ext-tokenizer": "*",
+                "ext-xmlwriter": "*",
+                "php": ">=5.4.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
+            },
+            "bin": [
+                "bin/phpcs",
+                "bin/phpcbf"
+            ],
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "3.x-dev"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "BSD-3-Clause"
+            ],
+            "authors": [
+                {
+                    "name": "Greg Sherwood",
+                    "role": "lead"
+                }
+            ],
+            "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
+            "homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
+            "keywords": [
+                "phpcs",
+                "standards"
+            ],
+            "time": "2019-04-10T23:49:02+00:00"
+        }
+    ],
     "aliases": [],
     "minimum-stability": "stable",
     "stability-flags": [],

+ 10 - 10
front/callback.php

@@ -5,7 +5,7 @@
 
 include ('../../../inc/includes.php');
 
-$params = [];
+$params = array();
 
 if (isset($_SERVER['PATH_INFO'])) {
    $path_info = trim($_SERVER['PATH_INFO'], '/');
@@ -42,15 +42,15 @@ if (!$signon_provider->fields['is_active']) {
    Html::displayErrorAndDie(__sso("Provider not active."), true);
 }
 
-$httpClient = new GuzzleHttp\Client([
+$httpClient = new GuzzleHttp\Client(array(
    'verify' => false,
-      ]);
+      ));
 
-$collaborators = [
+$collaborators = array(
    'httpClient' => $httpClient,
-];
+);
 
-$provider = $signon_provider->prepareProviderInstance([], $collaborators);
+$provider = $signon_provider->prepareProviderInstance(array(), $collaborators);
 
 $signon_provider->checkAuthorization();
 
@@ -90,14 +90,14 @@ if ($signon_provider->login()) {
 
 
 try {
-// Try to get an access token (using the authorization code grant)
-   $token = $provider->getAccessToken('authorization_code', [
+   // Try to get an access token (using the authorization code grant)
+   $token = $provider->getAccessToken('authorization_code', array(
       'code' => $_GET['code']
-   ]);
+   ));
 
    var_dump($token);
 
-// Optional: Now you have a token you can look up a users profile data
+   // Optional: Now you have a token you can look up a users profile data
    // We got an access token, let's now get the user's details
    $user = $provider->getResourceOwner($token);
 

+ 2 - 2
front/provider.form.php

@@ -3,7 +3,7 @@
 include ('../../../inc/includes.php');
 
 if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
-   Html::header("TITRE", $_SERVER['PHP_SELF'],"plugins","pluginexampleexample","");
+   Html::header("TITRE", $_SERVER['PHP_SELF'], "plugins", "pluginexampleexample", "");
 } else {
    Html::helpHeader("TITRE", $_SERVER['PHP_SELF']);
 }
@@ -12,4 +12,4 @@ $example = new PluginSinglesignonProvider();
 $example->display($_GET);
 
 Html::footer();
-?>
+

+ 1 - 1
front/provider.php

@@ -14,4 +14,4 @@ if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
 Search::show('PluginSinglesignonProvider');
 
 Html::footer();
-?>
+

+ 12 - 13
hook.php

@@ -12,12 +12,11 @@ function plugin_singlesignon_display_login() {
       $url_sufix = "/redirect/" . str_replace('/', '~', $_GET['redirect']);
    }
 
-
    $signon_provider = new PluginSinglesignonProvider();
 
    $rows = $signon_provider->find('`is_active` = 1');
 
-   $html = [];
+   $html = array();
 
    foreach ($rows as $row) {
       $html[] = '<a href="' . $url_prefix . '/provider/' . $row['id'] . $url_sufix . '" style="color: #CFCFCF">[ Login with ' . $row['name'] . ' ]</a>';
@@ -32,8 +31,8 @@ function plugin_singlesignon_install() {
 
    $currentVersion = '0.0.0';
 
-   $default = [
-   ];
+   $default = array(
+   );
 
    $current = Config::getConfigurationValues('singlesignon');
 
@@ -73,17 +72,17 @@ function plugin_singlesignon_install() {
 
       $DB->query($query) or die("error creating glpi_plugin_singlesignon_providers " . $DB->error());
 
-//      $query = "INSERT INTO `glpi_plugin_singlesignon_providers`
-//                       (`id`, `name`, `serial`, `is_deleted`)
-//                VALUES (1, 'example 1', 'serial 1', 0),
-//                       (2, 'example 2', 'serial 2', 0),
-//                       (3, 'example 3', 'serial 3', 0)";
-//      $DB->query($query) or die("error populate glpi_plugin_example " . $DB->error());
+      //      $query = "INSERT INTO `glpi_plugin_singlesignon_providers`
+      //                       (`id`, `name`, `serial`, `is_deleted`)
+      //                VALUES (1, 'example 1', 'serial 1', 0),
+      //                       (2, 'example 2', 'serial 2', 0),
+      //                       (3, 'example 3', 'serial 3', 0)";
+      //      $DB->query($query) or die("error populate glpi_plugin_example " . $DB->error());
    }
 
-   Config::setConfigurationValues('singlesignon', [
+   Config::setConfigurationValues('singlesignon', array(
       'version' => PLUGIN_SINGLESIGNON_VERSION,
-   ]);
+   ));
    return true;
 }
 
@@ -94,7 +93,7 @@ function plugin_singlesignon_uninstall() {
    $rows = $config->find("`context` LIKE 'singlesignon%'");
 
    foreach ($rows as $id => $row) {
-      $config->delete(['id' => $id]);
+      $config->delete(array('id' => $id));
    }
 
    // Old version tables

+ 30 - 30
inc/provider.class.php

@@ -49,17 +49,17 @@ class PluginSinglesignonProvider extends CommonDBTM {
       global $CFG_GLPI;
       $links = array();
 
-//      $links['add'] = '/plugins/singlesignon/front/provider.form.php';
-//      $links['config'] = '/plugins/singlesignon/index.php';
+      //      $links['add'] = '/plugins/singlesignon/front/provider.form.php';
+      //      $links['config'] = '/plugins/singlesignon/index.php';
       $links["<img  src='" . $CFG_GLPI["root_doc"] . "/pics/menu_showall.png' title='" . __s('Show all') . "' alt='" . __s('Show all') . "'>"] = '/plugins/singlesignon/index.php';
       $links[__s('Test link', 'singlesignon')] = '/plugins/singlesignon/index.php';
 
       return $links;
    }
 
-//   public function maybeTemplate() {
-//      parent::maybeTemplate();
-//   }
+   //   public function maybeTemplate() {
+   //      parent::maybeTemplate();
+   //   }
 
    function defineTabs($options = array()) {
 
@@ -262,14 +262,14 @@ class PluginSinglesignonProvider extends CommonDBTM {
       return '';
    }
 
-//////////////////////////////
-////// SPECIFIC MODIF MASSIVE FUNCTIONS ///////
+   //////////////////////////////
+   ////// SPECIFIC MODIF MASSIVE FUNCTIONS ///////
    /**
     * @since version 0.85
     *
     * @see CommonDBTM::getSpecificMassiveActions()
     * */
-   function getSpecificMassiveActions($checkitem = NULL) {
+   function getSpecificMassiveActions($checkitem = null) {
 
       $actions = parent::getSpecificMassiveActions($checkitem);
 
@@ -352,13 +352,13 @@ class PluginSinglesignonProvider extends CommonDBTM {
    }
 
    /**
-    * 
+    *
     * @param string $type
     * @param array $options
     * @param array $collaborators
     * @return \League\OAuth2\Client\Provider\AbstractProvider
     */
-   public static function createInstance($type = 'generic', array $options = [], array $collaborators = []) {
+   public static function createInstance($type = 'generic', array $options = array(), array $collaborators = array()) {
       switch ($type) {
          case 'facebook':
             if (!isset($options['graphApiVersion'])) {
@@ -391,7 +391,7 @@ class PluginSinglesignonProvider extends CommonDBTM {
       return $currentURL;
    }
 
-   public function prepareProviderInstance(array $options = [], array $collaborators = []) {
+   public function prepareProviderInstance(array $options = array(), array $collaborators = array()) {
       global $CFG_GLPI;
 
       if ($this->_provider === null) {
@@ -399,11 +399,11 @@ class PluginSinglesignonProvider extends CommonDBTM {
          $redirect_uri = $this->getCurrentURL();
 
          $type = $this->fields['type'];
-         $default = [
+         $default = array(
             'clientId'     => $this->fields['client_id'],
             'clientSecret' => $this->fields['client_secret'],
             'redirectUri'  => $redirect_uri,
-         ];
+         );
 
          if ($type === 'generic') {
             $default['urlAuthorize'] = $this->fields['url_authorize'];
@@ -414,11 +414,12 @@ class PluginSinglesignonProvider extends CommonDBTM {
          if (!empty($this->fields['extra_options'])) {
             try {
                $extra = json_decode($this->fields['extra_options'], true);
-               if (!empty($extra)) {
-                  $default = array_merge($default, $extra);
-               }
             } catch (Exception $ex) {
-               
+               $extra = array();
+            }
+
+            if (!empty($extra)) {
+               $default = array_merge($default, $extra);
             }
          }
          $options = array_merge($default, $options);
@@ -429,7 +430,7 @@ class PluginSinglesignonProvider extends CommonDBTM {
    }
 
    /**
-    * 
+    *
     * @return boolean|string
     */
    public function checkAuthorization() {
@@ -439,15 +440,15 @@ class PluginSinglesignonProvider extends CommonDBTM {
 
       if (!isset($_GET['code'])) {
 
-         $scope = [];
+         $scope = array();
          if (!empty($this->fields['scope'])) {
             $scope = explode(',', $this->fields['scope']);
          }
 
-         $options = [
+         $options = array(
             'scope' => $scope,
             'state' => Session::getNewCSRFToken(),
-         ];
+         );
 
          $this->_provider->authorize($options);
       }
@@ -455,9 +456,9 @@ class PluginSinglesignonProvider extends CommonDBTM {
       // Check given state against previously stored one to mitigate CSRF attack
       $state = isset($_GET['state']) ? $_GET['state'] : '';
 
-      Session::checkCSRF([
+      Session::checkCSRF(array(
          '_glpi_csrf_token' => $state,
-      ]);
+      ));
 
       $this->_code = $_GET['code'];
 
@@ -465,7 +466,7 @@ class PluginSinglesignonProvider extends CommonDBTM {
    }
 
    /**
-    * 
+    *
     * @return boolean|\League\OAuth2\Client\Token\AccessToken
     */
    public function getAccessToken() {
@@ -477,15 +478,15 @@ class PluginSinglesignonProvider extends CommonDBTM {
          return false;
       }
 
-      $this->_token = $this->_provider->getAccessToken('authorization_code', [
+      $this->_token = $this->_provider->getAccessToken('authorization_code', array(
          'code' => $this->_code
-      ]);
+      ));
 
       return $this->_token;
    }
 
    /**
-    * 
+    *
     * @return boolean|\League\OAuth2\Client\Provider\ResourceOwnerInterface
     */
    public function getResourceOwner() {
@@ -498,7 +499,6 @@ class PluginSinglesignonProvider extends CommonDBTM {
          return false;
       }
 
-
       $this->_resource_owner = $this->_provider->getResourceOwner($token);
 
       return $this->_resource_owner;
@@ -513,7 +513,7 @@ class PluginSinglesignonProvider extends CommonDBTM {
       //First: check linked user
 
       $email = false;
-      $email_fields = ['email', 'e-mail'];
+      $email_fields = array('email', 'e-mail');
 
       foreach ($email_fields as $field) {
          if (isset($resource_array[$field]) && is_string($resource_array[$field])) {
@@ -527,7 +527,7 @@ class PluginSinglesignonProvider extends CommonDBTM {
       }
 
       $login = false;
-      $login_fields = ['login', 'username'];
+      $login_fields = array('login', 'username');
 
       foreach ($login_fields as $field) {
          if (isset($resource_array[$field]) && is_string($resource_array[$field])) {

+ 2 - 2
setup.php

@@ -18,10 +18,10 @@ function plugin_init_singlesignon() {
 
    $PLUGIN_HOOKS['display_login']['singlesignon'] = "plugin_singlesignon_display_login";
 
-   $PLUGIN_HOOKS['menu_toadd']['singlesignon'] = [
+   $PLUGIN_HOOKS['menu_toadd']['singlesignon'] = array(
       'plugins' => 'PluginSinglesignonProvider',
       'config'  => 'PluginSinglesignonProvider',
-   ];
+   );
 }
 
 // Get the name and the version of the plugin - Needed