YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/WebserviceStandard/Users/AccessActivityHistory.php

Summary

Maintainability
A
1 hr
Test Coverage
B
87%

Method get has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function get(): array
    {
        $limit = 50;
        if ($requestLimit = $this->controller->request->getHeader('x-row-limit')) {
            $limit = (int) $requestLimit;
Severity: Minor
Found in api/webservice/WebserviceStandard/Users/AccessActivityHistory.php - About 1 hr to fix

    Missing class import via use statement (line '87', column '17').
    Open

            $query = (new \App\Db\Query())->select(['time', 'status', 'agent', 'ip'])

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Avoid using static access to class '\App\Language' in method 'get'.
    Open

                    'status' => \App\Language::translate($row['status'], 'Settings:WebserviceUsers'),

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid assigning values to variables in if clauses and the like (line '92', column '7').
    Open

        public function get(): array
        {
            $limit = 50;
            if ($requestLimit = $this->controller->request->getHeader('x-row-limit')) {
                $limit = (int) $requestLimit;

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid using static access to class '\App\Json' in method 'get'.
    Open

                $query->andWhere(\App\Json::decode($conditions));

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class '\App\Db' in method 'get'.
    Open

            $dataReader = $query->createCommand(\App\Db::getInstance('log'))->query();

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class '\App\Fields\DateTime' in method 'get'.
    Open

                    'time' => \App\Fields\DateTime::formatToDisplay($row['time']),

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid assigning values to variables in if clauses and the like (line '80', column '7').
    Open

        public function get(): array
        {
            $limit = 50;
            if ($requestLimit = $this->controller->request->getHeader('x-row-limit')) {
                $limit = (int) $requestLimit;

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid assigning values to variables in if clauses and the like (line '84', column '7').
    Open

        public function get(): array
        {
            $limit = 50;
            if ($requestLimit = $this->controller->request->getHeader('x-row-limit')) {
                $limit = (int) $requestLimit;

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Define a constant instead of duplicating this literal "agent" 3 times.
    Open

            $query = (new \App\Db\Query())->select(['time', 'status', 'agent', 'ip'])

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define a constant instead of duplicating this literal "status" 3 times.
    Open

            $query = (new \App\Db\Query())->select(['time', 'status', 'agent', 'ip'])

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Call to undeclared method \App\Db\Query::select
    Open

            $query = (new \App\Db\Query())->select(['time', 'status', 'agent', 'ip'])

    Possibly zero references to use statement for classlike/namespace OA (\OpenApi\Annotations)
    Open

    use OpenApi\Annotations as OA;

    Spaces must be used for alignment; tabs are not allowed
    Open

        /** {@inheritdoc}  */

    Spaces must be used for alignment; tabs are not allowed
    Open

        protected function checkPermissionToModule(): void

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="x-row-limit", in="header", @OA\Schema(type="integer"), description="Get rows limit, default: 50", required=false, example=1000),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="x-row-offset", in="header", @OA\Schema(type="integer"), description="Offset, default: 0", required=false, example=0),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

     * @license    YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)

    Spaces must be used for alignment; tabs are not allowed
    Open

        /**

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    @OA\Schema(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        title="Users module - History of access activity data",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        required={"status", "result"},

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            title="User data",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\JsonContent(ref="#/components/schemas/Users_Get_AccessActivityHistory_Response"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\JsonContent(ref="#/components/schemas/Conditions-For-Native-Query"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            title="User data",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Property(property="time", type="string", description="Date time in user format", example="2021-06-01 11:57"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="x-condition", in="header", description="Conditions [Json format]", required=false,

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\XmlContent(ref="#/components/schemas/Users_Get_AccessActivityHistory_Response"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Property(property="time", type="string", description="Date time in user format", example="2021-06-01 11:57"),

    Spaces must be used for alignment; tabs are not allowed
    Open

        {

    Spaces must be used for alignment; tabs are not allowed
    Open

        public $allowedMethod = ['GET'];

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        path="/webservice/WebserviceStandard/Users/AccessActivityHistory",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        title="Users module - History of access activity data",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Response(response=200, description="User history of access activity",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\AdditionalProperties(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        summary="History of access activity data",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        security={{"basicAuth" : {}, "ApiKeyAuth" : {}, "token" : {}}},

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        required={"status", "result"},

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                title="Condition details",

    Spaces must be used for alignment; tabs are not allowed
    Open

        public $allowedHeaders = ['x-condition', 'x-row-offset', 'x-row-limit'];

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    @OA\Get(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        security={{"basicAuth" : {}, "ApiKeyAuth" : {}, "token" : {}}},

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(property="status", type="integer", enum={0, 1}, description="A numeric value of 0 or 1 that indicates whether the communication is valid. 1 - success , 0 - error"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        description="Get user history of access activity",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="x-condition", in="header", description="Conditions [Json format]", required=false,

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\XmlContent(ref="#/components/schemas/Users_Get_AccessActivityHistory_Response"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    @OA\Schema(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            property="result",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\AdditionalProperties(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Property(property="agent", type="string", description="User agent", example="PostmanRuntime/7.28.0"),

    Spaces must be used for alignment; tabs are not allowed
    Open

        /** {@inheritdoc}  */

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="x-row-limit", in="header", @OA\Schema(type="integer"), description="Get rows limit, default: 50", required=false, example=1000),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                title="Condition details",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        tags={"Users"},

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="x-row-offset", in="header", @OA\Schema(type="integer"), description="Offset, default: 0", required=false, example=0),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\JsonContent(ref="#/components/schemas/Conditions-For-Native-Query"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        schema="Users_Get_AccessActivityHistory_Response",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        schema="Users_Get_AccessActivityHistory_Response",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Property(property="status", type="string", description="Operation name", example="Signed in"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         * Get user history of access activity.

    Spaces must be used for alignment; tabs are not allowed
    Open

         * @api

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        tags={"Users"},

    Spaces must be used for alignment; tabs are not allowed
    Open

     * @author    Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>

    Spaces must be used for alignment; tabs are not allowed
    Open

        /** {@inheritdoc}  */

    Spaces must be used for alignment; tabs are not allowed
    Open

        }

    Spaces must be used for alignment; tabs are not allowed
    Open

         *

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        description="Get user history of access activity",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        summary="History of access activity data",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\JsonContent(ref="#/components/schemas/Users_Get_AccessActivityHistory_Response"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(property="status", type="integer", enum={0, 1}, description="A numeric value of 0 or 1 that indicates whether the communication is valid. 1 - success , 0 - error"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         * @return array

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    @OA\Get(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        path="/webservice/WebserviceStandard/Users/AccessActivityHistory",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Response(response=200, description="User history of access activity",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            property="result",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Property(property="status", type="string", description="Operation name", example="Signed in"),

    Spaces must be used for alignment; tabs are not allowed
    Open

            if ($requestLimit = $this->controller->request->getHeader('x-row-limit')) {

    Spaces must be used for alignment; tabs are not allowed
    Open

            $rows = [];

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            ),

    Spaces must be used for alignment; tabs are not allowed
    Open

            $limit = 50;

    Spaces must be used for alignment; tabs are not allowed
    Open

        public function get(): array

    Spaces must be used for alignment; tabs are not allowed
    Open

                ->orderBy(['id' => SORT_DESC])

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Property(property="ip", type="string", description="IP address", example="127.0.0.1"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

                ->from($this->controller->app['tables']['loginHistory'])

    Spaces must be used for alignment; tabs are not allowed
    Open

            $dataReader = $query->createCommand(\App\Db::getInstance('log'))->query();

    Spaces must be used for alignment; tabs are not allowed
    Open

            if ($requestOffset = $this->controller->request->getHeader('x-row-offset')) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                $query->andWhere(\App\Json::decode($conditions));

    Spaces must be used for alignment; tabs are not allowed
    Open

                $rows[] = [

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Property(property="ip", type="string", description="IP address", example="127.0.0.1"),

    Spaces must be used for alignment; tabs are not allowed
    Open

        {

    Spaces must be used for alignment; tabs are not allowed
    Open

                ];

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

                $limit = (int) $requestLimit;

    Spaces must be used for alignment; tabs are not allowed
    Open

                ->where(['user_id' => $this->getUserData('id')])

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

            while ($row = $dataReader->read()) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                    'agent' => $row['agent'],

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

            $offset = 0;

    Spaces must be used for alignment; tabs are not allowed
    Open

                ->limit($limit)->offset($offset);

    Spaces must be used for alignment; tabs are not allowed
    Open

                    'ip' => $row['ip'],

    Spaces must be used for alignment; tabs are not allowed
    Open

        }

    Spaces must be used for alignment; tabs are not allowed
    Open

            $dataReader->close();

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Property(property="agent", type="string", description="User agent", example="PostmanRuntime/7.28.0"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         */

    Spaces must be used for alignment; tabs are not allowed
    Open

                $offset = (int) $requestOffset;

    Spaces must be used for alignment; tabs are not allowed
    Open

            $query = (new \App\Db\Query())->select(['time', 'status', 'agent', 'ip'])

    Spaces must be used for alignment; tabs are not allowed
    Open

            if ($conditions = $this->controller->request->getHeader('x-condition')) {

    Spaces must be used for alignment; tabs are not allowed
    Open

            return $rows;

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

                    'time' => \App\Fields\DateTime::formatToDisplay($row['time']),

    Spaces must be used for alignment; tabs are not allowed
    Open

                    'status' => \App\Language::translate($row['status'], 'Settings:WebserviceUsers'),

    Line exceeds 120 characters; contains 189 characters
    Open

         *        @OA\Property(property="status", type="integer", enum={0, 1}, description="A numeric value of 0 or 1 that indicates whether the communication is valid. 1 - success , 0 - error"),

    Line exceeds 120 characters; contains 160 characters
    Open

         *        @OA\Parameter(name="x-row-limit", in="header", @OA\Schema(type="integer"), description="Get rows limit, default: 50", required=false, example=1000),

    Line exceeds 120 characters; contains 133 characters
    Open

         *                @OA\Property(property="time", type="string", description="Date time in user format", example="2021-06-01 11:57"),

    Line exceeds 120 characters; contains 131 characters
    Open

         *        @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),

    Line exceeds 120 characters; contains 149 characters
    Open

         *        @OA\Parameter(name="x-row-offset", in="header", @OA\Schema(type="integer"), description="Offset, default: 0", required=false, example=0),

    Line exceeds 120 characters; contains 125 characters
    Open

         *                @OA\Property(property="agent", type="string", description="User agent", example="PostmanRuntime/7.28.0"),

    There are no issues that match your filters.

    Category
    Status