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

AJenbo / agcms / 21420560247

28 Jan 2026 12:59AM UTC coverage: 52.306% (-1.4%) from 53.72%
21420560247

push

github

AJenbo
Bump phpunit/phpunit from 9.6.11 to 9.6.33 in /application

Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.6.11 to 9.6.33.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/9.6.33/ChangeLog-9.6.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.6.11...9.6.33)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-version: 9.6.33
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

3039 of 5810 relevant lines covered (52.31%)

12.21 hits per line

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

32.35
/application/inc/Models/File.php
1
<?php
2

3
namespace App\Models;
4

5
use App\Exceptions\Exception;
6
use App\Exceptions\InvalidInput;
7
use App\Services\DbService;
8
use App\Services\OrmService;
9
use Symfony\Component\Mime\MimeTypes;
10

11
class File extends AbstractEntity
12
{
13
    /** Table name in database. */
14
    public const TABLE_NAME = 'files';
15

16
    // Backed by DB
17

18
    /** @var string File path. */
19
    private string $path;
20

21
    /** @var string File mime. */
22
    private string $mime;
23

24
    /** @var int File byte size. */
25
    private int $size;
26

27
    /** @var string Text description of file. */
28
    private string $description = '';
29

30
    /** @var int Object width in px. */
31
    private int $width = 0;
32

33
    /** @var int Object height in px. */
34
    private int $height = 0;
35

36
    public function __construct(array $data = [])
37
    {
38
        $this->setPath(valstring($data['path']))
9✔
39
            ->setMime(valstring($data['mime']))
9✔
40
            ->setSize(valint($data['size']))
9✔
41
            ->setDescription(valstring($data['description']))
9✔
42
            ->setWidth(valint($data['width']))
9✔
43
            ->setHeight(valint($data['height']))
9✔
44
            ->setId(intOrNull($data['id'] ?? null));
9✔
45
    }
46

47
    public static function mapFromDB(array $data): array
48
    {
49
        return [
9✔
50
            'id'          => $data['id'],
9✔
51
            'path'        => $data['path'],
9✔
52
            'mime'        => $data['mime'],
9✔
53
            'size'        => $data['size'],
9✔
54
            'description' => $data['alt'],
9✔
55
            'width'       => $data['width'],
9✔
56
            'height'      => $data['height'],
9✔
57
        ];
9✔
58
    }
59

60
    // Getters and setters
61

62
    /**
63
     * @return $this
64
     */
65
    private function setPath(string $path): self
66
    {
67
        $this->path = $path;
9✔
68

69
        return $this;
9✔
70
    }
71

72
    public function getPath(): string
73
    {
74
        return $this->path;
5✔
75
    }
76

77
    /**
78
     * @return $this
79
     */
80
    public function setMime(string $mime): self
81
    {
82
        $this->mime = $mime;
9✔
83

84
        return $this;
9✔
85
    }
86

87
    public function getMime(): string
88
    {
89
        return $this->mime;
1✔
90
    }
91

92
    /**
93
     * @param int $size The file size in bytes
94
     *
95
     * @return $this
96
     */
97
    public function setSize(int $size): self
98
    {
99
        $this->size = $size;
9✔
100

101
        return $this;
9✔
102
    }
103

104
    /**
105
     * Get the file size.
106
     */
107
    public function getSize(): int
108
    {
109
        return $this->size;
×
110
    }
111

112
    /**
113
     * @return $this
114
     */
115
    public function setDescription(string $description): self
116
    {
117
        $this->description = $description;
9✔
118

119
        return $this;
9✔
120
    }
121

122
    /**
123
     * Get the text description.
124
     */
125
    public function getDescription(): string
126
    {
127
        return $this->description;
4✔
128
    }
129

130
    /**
131
     * Set display width.
132
     *
133
     * @return $this
134
     */
135
    public function setWidth(int $width): self
136
    {
137
        $this->width = $width;
9✔
138

139
        return $this;
9✔
140
    }
141

142
    /**
143
     * Get display width.
144
     */
145
    public function getWidth(): int
146
    {
147
        return $this->width;
4✔
148
    }
149

150
    /**
151
     * Set display height.
152
     *
153
     * @return $this
154
     */
155
    public function setHeight(int $height): self
156
    {
157
        $this->height = $height;
9✔
158

159
        return $this;
9✔
160
    }
161

162
    /**
163
     * Get display height.
164
     */
165
    public function getHeight(): int
166
    {
167
        return $this->height;
4✔
168
    }
169

170
    // ORM related functions
171

172
    public function getDbArray(): array
173
    {
174
        $db = app(DbService::class);
×
175

176
        return [
×
177
            'path'   => $db->quote($this->path),
×
178
            'mime'   => $db->quote($this->mime),
×
179
            'size'   => (string)$this->size,
×
180
            'alt'    => $db->quote($this->description),
×
181
            'width'  => (string)$this->width,
×
182
            'height' => (string)$this->height,
×
183
        ];
×
184
    }
185

186
    /**
187
     * Rename file.
188
     */
189
    public function move(string $path): bool
190
    {
191
        $app = app();
×
192

193
        //Rename/move or give an error
194
        if (!rename($app->basePath($this->getPath()), $app->basePath($path))) {
×
195
            return false;
×
196
        }
197

198
        $this->replacePaths($this->getPath(), $path);
×
199
        $this->setPath($path)->save();
×
200

201
        return true;
×
202
    }
203

204
    /**
205
     * Update related data.
206
     */
207
    private function replacePaths(string $path, string $newPath): void
208
    {
209
        $db = app(DbService::class);
×
210

211
        $newPathEsc = $db->quote('="' . $newPath . '"');
×
212
        $pathEsc = $db->quote('="' . $path . '"');
×
213
        $db->query('UPDATE sider     SET text = REPLACE(text, ' . $pathEsc . ', ' . $newPathEsc . ')');
×
214
        $db->query('UPDATE template  SET text = REPLACE(text, ' . $pathEsc . ', ' . $newPathEsc . ')');
×
215
        $db->query('UPDATE special   SET text = REPLACE(text, ' . $pathEsc . ', ' . $newPathEsc . ')');
×
216
        $db->query('UPDATE krav      SET text = REPLACE(text, ' . $pathEsc . ', ' . $newPathEsc . ')');
×
217
        $db->query('UPDATE newsmails SET text = REPLACE(text, ' . $pathEsc . ', ' . $newPathEsc . ')');
×
218
    }
219

220
    /**
221
     * Check if file is in use.
222
     */
223
    public function isInUse(bool $onlyCheckHtml = false): bool
224
    {
225
        $db = app(DbService::class);
×
226

227
        $escapedPath = $db->quote('%="' . $this->path . '"%');
×
228

229
        $sql = "
×
230
              (SELECT id FROM `sider`     WHERE `text` LIKE $escapedPath LIMIT 1)
×
231
        UNION (SELECT id FROM `template`  WHERE `text` LIKE $escapedPath LIMIT 1)
×
232
        UNION (SELECT id FROM `special`   WHERE `text` LIKE $escapedPath LIMIT 1)
×
233
        UNION (SELECT id FROM `krav`      WHERE `text` LIKE $escapedPath LIMIT 1)
×
234
        UNION (SELECT id FROM `newsmails` WHERE `text` LIKE $escapedPath LIMIT 1)
×
235
        ";
×
236
        $db->addLoadedTable('sider', 'template', 'special', 'krav', 'newsmails');
×
237

238
        if (!$onlyCheckHtml) {
×
239
            $sql .= '
×
240
            UNION (SELECT id FROM `sider`    WHERE `icon_id` = ' . $this->getId() . ' LIMIT 1)
×
241
            UNION (SELECT id FROM `template` WHERE `icon_id` = ' . $this->getId() . ' LIMIT 1)
×
242
            UNION (SELECT id FROM `maerke`   WHERE `icon_id` = ' . $this->getId() . ' LIMIT 1)
×
243
            UNION (SELECT id FROM `kat`      WHERE `icon_id` = ' . $this->getId() . ' LIMIT 1)
×
244
            ';
×
245
            $db->addLoadedTable('kat');
×
246
        }
247

248
        return (bool)$db->fetchOne($sql);
×
249
    }
250

251
    /**
252
     * Create new File from a file path.
253
     *
254
     * @todo Load size of video
255
     *
256
     * @return static
257
     */
258
    public static function fromPath(string $path): self
259
    {
260
        $fullPath = app()->basePath($path);
×
261
        $imagesize = @getimagesize($fullPath);
×
262
        if (!$imagesize) {
×
263
            $imagesize = [];
×
264
        }
265

266
        $guesser = new MimeTypes();
×
267
        $mime = $guesser->guessMimeType($fullPath);
×
268

269
        $file = new static([
×
270
            'path'        => $path,
×
271
            'mime'        => $mime,
×
272
            'size'        => filesize($fullPath),
×
273
            'description' => '',
×
274
            'width'       => $imagesize[0] ?? 0,
×
275
            'height'      => $imagesize[1] ?? 0,
×
276
        ]);
×
277

278
        return $file;
×
279
    }
280

281
    /**
282
     * Delete entity and file.
283
     *
284
     * @throws Exception
285
     * @throws InvalidInput
286
     */
287
    public function delete(): bool
288
    {
289
        if ($this->isInUse()) {
×
290
            throw new InvalidInput(sprintf(_('"%s" is still in use.'), $this->path), 423);
×
291
        }
292

293
        $app = app();
×
294

295
        if (file_exists($app->basePath($this->path)) && !unlink($app->basePath($this->path))) {
×
296
            throw new Exception(sprintf(_('Could not delete "%s".'), $this->path), 403);
×
297
        }
298

299
        return parent::delete();
×
300
    }
301

302
    public static function getByPath(string $path): ?self
303
    {
304
        $file = app(OrmService::class)->getOneByQuery(
×
305
            static::class,
×
306
            'SELECT * FROM `' . self::TABLE_NAME . '` WHERE path = ' . app(DbService::class)->quote($path)
×
307
        );
×
308

309
        return $file;
×
310
    }
311
}
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