AuthService   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 12 1
A _actionOptions() 0 6 1
1
<?php
2
/**
3
 * Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
4
 *
5
 * Licensed under The MIT License
6
 * Redistributions of files must retain the above copyright notice.
7
 *
8
 * @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
9
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10
 */
11
12
namespace CakeDC\Api\Service;
13
14
use CakeDC\Api\Service\Action\Auth\LoginAction;
15
use CakeDC\Api\Service\Action\Auth\RegisterAction;
16
use CakeDC\Api\Service\Action\Auth\ResetPasswordAction;
17
use CakeDC\Api\Service\Action\Auth\ResetPasswordRequestAction;
18
use CakeDC\Api\Service\Action\Auth\SocialLoginAction;
19
use CakeDC\Api\Service\Action\Auth\ValidateAccountAction;
20
use CakeDC\Api\Service\Action\Auth\ValidateAccountRequestAction;
21
use Cake\Utility\Hash;
22
23
/**
24
 * Class AuthService
25
 *
26
 * @package CakeDC\Api\Service
27
 */
28
class AuthService extends Service
29
{
30
31
    /**
32
     * @inheritdoc
33
     * @return void
34
     */
35 8
    public function initialize()
36
    {
37 8
        parent::initialize();
38 8
        $methods = ['method' => ['POST'], 'mapCors' => true];
39 8
        $this->mapAction('login', LoginAction::class, $methods);
40 8
        $this->mapAction('register', RegisterAction::class, $methods);
41 8
        $this->mapAction('reset_password_request', ResetPasswordRequestAction::class, $methods);
42 8
        $this->mapAction('reset_password', ResetPasswordAction::class, $methods);
43 8
        $this->mapAction('validate_account_request', ValidateAccountRequestAction::class, $methods);
44 8
        $this->mapAction('validate_account', ValidateAccountAction::class, $methods);
45 8
        $this->mapAction('social_login', SocialLoginAction::class, $methods);
46 8
    }
47
48
    /**
49
     * Action constructor options.
50
     *
51
     * @param array $route Action route.
52
     * @return array
53
     */
54 8
    protected function _actionOptions($route)
55
    {
56 8
        $options['Extension'] = ['CakeDC/Api.Auth/UserFormatting'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
57
58 8
        return Hash::merge(parent::_actionOptions($route), $options);
59
    }
60
}
61