Apps   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 28
c 2
b 0
f 0
dl 0
loc 75
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 33 2
1
<?php
2
3
namespace Canvas\Cli\Jobs;
4
5
use Canvas\Contracts\Queue\QueueableJobInterface;
6
use Canvas\Jobs\Job;
7
use Phalcon\Di;
8
use Canvas\Models\Apps as CanvasApps;
9
use Phalcon\Security\Random;
0 ignored issues
show
Bug introduced by
The type Phalcon\Security\Random was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class Apps extends Job implements QueueableJobInterface
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
38
     * @param string $event
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
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type void.
Loading history...
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
Comprehensibility Best Practice introduced by
The variable $appName seems to be never defined.
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression return true returns the type true which is incompatible with the documented return type void.
Loading history...
86
    }
87
}
88