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

mixerapi / mixerapi-dev / 7434143287

06 Jan 2024 09:54PM UTC coverage: 94.68% (-1.1%) from 95.793%
7434143287

Pull #141

github

web-flow
Merge 4d1f37519 into 39576a822
Pull Request #141: CakePHP 5 support

961 of 1015 relevant lines covered (94.68%)

4.4 hits per line

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

86.67
/plugins/collection-view/src/View/JsonCollectionView.php
1
<?php
2
declare(strict_types=1);
3

4
namespace MixerApi\CollectionView\View;
5

6
use Cake\Core\Configure;
7
use Cake\View\JsonView;
8
use MixerApi\CollectionView\Serializer;
9

10
class JsonCollectionView extends JsonView
11
{
12
    /**
13
     * @inheritDoc
14
     */
15
    protected string $layoutPath = 'json';
16

17
    /**
18
     * @inheritDoc
19
     */
20
    protected string $subDir = 'json';
21

22
    /**
23
     * @inheritDoc
24
     */
25
    protected array $_defaultConfig = [
26
        'serialize' => null,
27
        'jsonOptions' => null,
28
    ];
29

30
    /**
31
     * @inheritDoc
32
     */
33
    public function initialize(): void
34
    {
35
        parent::initialize();
3✔
36
        $this->loadHelper('Paginator', [
3✔
37
            'templates' => 'MixerApi/CollectionView.paginator-template',
3✔
38
        ]);
3✔
39
    }
40

41
    /**
42
     * @inheritDoc
43
     */
44
    protected function _serialize($serialize): string
45
    {
46
        $serialize = $this->_dataToSerialize($serialize);
1✔
47

48
        $jsonOptions = $this->getConfig('jsonOptions');
1✔
49

50
        if ($jsonOptions === null) {
1✔
51
            $jsonOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_PARTIAL_OUTPUT_ON_ERROR;
1✔
52
        } elseif ($jsonOptions === false) {
×
53
            $jsonOptions = 0;
×
54
        }
55

56
        if (Configure::read('debug')) {
1✔
57
            $jsonOptions |= JSON_PRETTY_PRINT;
1✔
58
        }
59

60
        if (defined('JSON_THROW_ON_ERROR')) {
1✔
61
            $jsonOptions |= JSON_THROW_ON_ERROR;
1✔
62
        }
63

64
        return (new Serializer($serialize, $this->getRequest(), $this->Paginator))->asJson($jsonOptions);
1✔
65
    }
66
}
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