Failed Conditions
Push — master ( a14178...a46e0a )
by Maximo
01:03 queued 12s
created

Apps::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 34
rs 9.376
c 0
b 0
f 0
1
<?php
2
3
namespace Canvas\Cli\Jobs;
4
5
use Canvas\Contracts\Queue\QueueableJobInterfase;
6
use Canvas\Jobs\Job;
7
use Phalcon\Di;
8
use Canvas\Models\Apps as CanvasApps;
9
use Phalcon\Security\Random;
10
11
class Apps extends Job implements QueueableJobInterfase
12
{
13
    /**
14
     * Realtime channel
15
     *
16
     * @var string
17
     */
18
    protected $appName;
19
20
    /**
21
     * Realtime event
22
     *
23
     * @var string
24
     */
25
    protected $appDescription;
26
27
    /**
28
     * Realtime params
29
     *
30
     * @var array
31
     */
32
    protected $params;
33
34
    /**
35
     * Constructor setup info for Pusher
36
     *
37
     * @param string $channel
0 ignored issues
show
Bug introduced by
There is no parameter named $channel. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
38
     * @param string $event
0 ignored issues
show
Bug introduced by
There is no parameter named $event. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
39
     * @param array $params
40
     */
41
    public function __construct(string $appName, string $appDescription, array $params)
42
    {
43
        $this->appName = $appName;
44
        $this->appDescription = $appDescription;
45
        $this->params = $params;
46
    }
47
48
    /**
49
     * Handle the pusher request
50
     * @todo New Apps can't be created, the system does not take into account the creation of other apps apart from the default. Need to change this
51
     * @return void
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
52
     */
53
    public function handle()
54
    {
55
        $random = new Random();
56
        $appDescription = $this->appDescription;
57
58
        $app = new CanvasApps();
59
        $app->name = $this->appName;
60
        $app->description = $appDescription;
61
        $app->key = $random->uuid();
62
        $app->is_public = 1;
63
        $app->default_apps_plan_id = 1;
64
        $app->created_at = date('Y-m-d H:i:s');
65
        $app->is_deleted = 0;
66
        $app->payments_active = 0;
67
68
        if (!$app->save()) {
69
            Di::getDefault()->getLog()->error('App could not be created');
70
            return false;
71
        }
72
73
        /**
74
         * @todo Only works for default app
75
         */
76
        Di::getDefault()->getAcl()->setApp($app);
77
78
        Di::getDefault()->getAcl()->addRole($appName .'.Admins');
0 ignored issues
show
Bug introduced by
The variable $appName does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
79
        Di::getDefault()->getAcl()->addRole($appName .'.Agents');
80
        Di::getDefault()->getAcl()->addRole($appName .'.Users');
81
82
        Di::getDefault()->getAcl()->addResource($appName .'.Users', ['read', 'list', 'create', 'update', 'delete']);
83
        Di::getDefault()->getAcl()->allow('Admins', $appName .'.Users', ['read', 'list', 'create', 'update', 'delete']);
84
85
        return true;
86
    }
87
}
88