ManagesCronChecks   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 26
dl 0
loc 67
rs 10
c 2
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A cronChecks() 0 5 1
A updateCronCheck() 0 5 1
A createSimpleCronCheck() 0 16 1
A deleteCronCheck() 0 3 1
A createCronCheck() 0 18 1
A syncCronChecks() 0 7 1
1
<?php
2
3
namespace OhDear\PhpSdk\Actions;
4
5
use OhDear\PhpSdk\Resources\CronCheck;
6
7
trait ManagesCronChecks
8
{
9
    public function cronChecks(int $siteId)
10
    {
11
        return $this->transformCollection(
0 ignored issues
show
Bug introduced by
It seems like transformCollection() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

11
        return $this->/** @scrutinizer ignore-call */ transformCollection(
Loading history...
12
            $this->get("sites/{$siteId}/cron-checks")['data'],
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

12
            $this->/** @scrutinizer ignore-call */ 
13
                   get("sites/{$siteId}/cron-checks")['data'],
Loading history...
13
            CronCheck::class
14
        );
15
    }
16
17
    public function createSimpleCronCheck(
18
        int $siteId,
19
        string $name,
20
        int $frequencyInMinutes,
21
        int $graceTimeInMinutes,
22
        string $description
23
    ): CronCheck {
24
        $attributes = $this->post("sites/{$siteId}/cron-checks", [
0 ignored issues
show
Bug introduced by
It seems like post() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        /** @scrutinizer ignore-call */ 
25
        $attributes = $this->post("sites/{$siteId}/cron-checks", [
Loading history...
25
            'name' => $name,
26
            'type' => 'simple',
27
            'frequency_in_minutes' => $frequencyInMinutes,
28
            'grace_time_in_minutes' => $graceTimeInMinutes,
29
            'description' => $description,
30
        ]);
31
32
        return new CronCheck($attributes, $this);
33
    }
34
35
    public function createCronCheck(
36
        int $siteId,
37
        string $name,
38
        string $cronExpression,
39
        int $graceTimeInMinutes,
40
        string $description,
41
        string $serverTimezone
42
    ): CronCheck {
43
        $attributes = $this->post("sites/{$siteId}/cron-checks", [
44
            'name' => $name,
45
            'type' => 'cron',
46
            'cron_expression' => $cronExpression,
47
            'grace_time_in_minutes' => $graceTimeInMinutes,
48
            'description' => $description,
49
            'server_timezone' => $serverTimezone,
50
        ]);
51
52
        return new CronCheck($attributes, $this);
53
    }
54
55
    public function updateCronCheck(int $cronCheckId, array $payload): CronCheck
56
    {
57
        $attributes = $this->put("cron-checks/{$cronCheckId}", $payload);
0 ignored issues
show
Bug introduced by
It seems like put() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        /** @scrutinizer ignore-call */ 
58
        $attributes = $this->put("cron-checks/{$cronCheckId}", $payload);
Loading history...
58
59
        return new CronCheck($attributes, $this);
60
    }
61
62
    public function deleteCronCheck(int $cronCheckId): void
63
    {
64
        $this->delete("cron-checks/{$cronCheckId}");
0 ignored issues
show
Bug introduced by
The method delete() does not exist on OhDear\PhpSdk\Actions\ManagesCronChecks. Did you maybe mean deleteCronCheck()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        $this->/** @scrutinizer ignore-call */ 
65
               delete("cron-checks/{$cronCheckId}");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
    }
66
67
    public function syncCronChecks(int $siteId, array $cronCheckAttributes): array
68
    {
69
        $response = $this->post("sites/{$siteId}/cron-checks/sync", ['cron_checks' => $cronCheckAttributes]);
70
71
        return $this->transformCollection(
72
            $response,
73
            CronCheck::class,
74
        );
75
    }
76
}
77