• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daycry / cronjob / 15775568161

20 Jun 2025 09:13AM UTC coverage: 69.514% (+4.1%) from 65.424%
15775568161

push

github

daycry
- New Features

130 of 163 new or added lines in 9 files covered. (79.75%)

6 existing lines in 3 files now uncovered.

415 of 597 relevant lines covered (69.51%)

3.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.19
/src/Traits/StatusTrait.php
1
<?php
2

3
namespace Daycry\CronJob\Traits;
4

5
use DateTime;
6
use Daycry\CronJob\Job;
7

8
/**
9
 * Trait StatusTrait
10
 *
11
 * @mixin Job
12
 */
13
trait StatusTrait
14
{
15
    protected function isRunningFlagPath(): string
16
    {
17
        return $this->config->filePath . 'running/' . $this->getName();
6✔
18
    }
19

20
    protected function createFolderIfNotExists(string $folder): void
21
    {
22
        if (! is_dir($folder)) {
6✔
23
            mkdir($folder, 0777, true);
1✔
24
        }
25
    }
26

27
    protected function createFoldersIfNeeded(): void
28
    {
29
        $this->createFolderIfNotExists($this->config->filePath);
6✔
30
        $this->createFolderIfNotExists($this->config->filePath . 'running');
6✔
31
    }
32

33
    /**
34
     * Saves the running flag.
35
     *
36
     * @param mixed $flag
37
     *
38
     * @return array|false
39
     */
40
    public function saveRunningFlag($flag)
41
    {
42
        $path = $this->isRunningFlagPath();
6✔
43

44
        if ($flag) {
6✔
45
            if (file_exists($path)) {
6✔
46
                return false;
×
47
            }
48

49
            $this->createFoldersIfNeeded();
6✔
50

51
            $data = [
6✔
52
                'flag' => $flag,
6✔
53
                'time' => (new DateTime())->format('Y-m-d H:i:s'),
6✔
54
            ];
6✔
55

56
            file_put_contents($path, json_encode($data, JSON_PRETTY_PRINT));
6✔
57

58
            return $data;
6✔
59
        }
60

61
        @unlink($path);
6✔
62

63
        return false;
6✔
64
    }
65

66
    /**
67
     * Get cronjob status
68
     */
69
    public function status(): bool
70
    {
71
        $name = $this->getName();
6✔
72

73
        return ! is_dir($this->config->filePath) || ! is_dir($this->config->filePath . 'disable/') || ! file_exists($this->config->filePath . 'disable/' . $name);
6✔
74
    }
75

76
    /**
77
     * Disable cronjob
78
     */
79
    public function disable(): bool
80
    {
NEW
81
        $name        = $this->getName();
×
82
        $disablePath = $this->config->filePath . 'disable/' . $name;
×
83

NEW
84
        if (! file_exists($disablePath)) {
×
85
            $this->createFolderIfNotExists($this->config->filePath . 'disable');
×
86

87
            $data = [
×
88
                'name' => $name,
×
89
                'time' => (new DateTime())->format('Y-m-d H:i:s'),
×
90
            ];
×
91

92
            file_put_contents($disablePath, json_encode($data, JSON_PRETTY_PRINT));
×
93

94
            return true;
×
95
        }
96

97
        return false;
×
98
    }
99

100
    /**
101
     * Enable cronjob
102
     */
103
    public function enable(): bool
104
    {
NEW
105
        $name        = $this->getName();
×
106
        $disablePath = $this->config->filePath . 'disable/' . $name;
×
107

108
        if (file_exists($disablePath)) {
×
109
            @unlink($disablePath);
×
110

111
            return true;
×
112
        }
113

114
        return false;
×
115
    }
116

117
    /**
118
     * @return ?array{
119
     *     name: string,
120
     *     time: string,
121
     * }
122
     */
123
    public function getIsRunningInfo(): ?array
124
    {
125
        $path = $this->isRunningFlagPath();
×
126

NEW
127
        if (! file_exists($path)) {
×
128
            return null;
×
129
        }
130

131
        $content = file_get_contents($path);
×
132

133
        return json_decode($content, true);
×
134
    }
135

136
    private function getName(): string
137
    {
138
        return $this->name ?: $this->buildName();
×
139
    }
140
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc