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

JBZoo / Data / 7796885268

28 Jan 2024 08:47AM UTC coverage: 98.958%. Remained the same
7796885268

push

github

web-flow
Add PHP 8.3 support and update dependencies in composer.json (#31)

190 of 192 relevant lines covered (98.96%)

38.97 hits per line

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

93.75
/src/PhpArray.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - Data.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/Data
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\Data;
18

19
final class PhpArray extends AbstractData
20
{
21
    /**
22
     * @param null|false|string|string[] $data The data array
23
     */
24
    public function __construct($data = [])
25
    {
26
        if (\is_string($data) && $data !== '' && \file_exists($data)) {
24✔
27
            $data = $this->decode($data);
24✔
28
        }
29

30
        if ($data === false || $data === null) {
24✔
31
            $data = [];
×
32
        }
33

34
        parent::__construct($data);
24✔
35
    }
36

37
    protected function decode(string $string): mixed
38
    {
39
        if (\file_exists($string)) {
24✔
40
            return include $string;
24✔
41
        }
42

43
        return [];
6✔
44
    }
45

46
    protected function encode(array $data): string
47
    {
48
        $data = [
12✔
49
            '<?php',
12✔
50
            '',
12✔
51
            'declare(strict_types=1);',
12✔
52
            '',
12✔
53
            'return ' . \var_export($data, true) . ';',
12✔
54
        ];
12✔
55

56
        return \implode(self::LE, $data);
12✔
57
    }
58
}
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

© 2025 Coveralls, Inc