Test Failed
Push — master ( 5fcf14...625fb6 )
by Adrian Florin
04:15 queued 01:51
created

JsonContent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of the NeedleProject\FileIo package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
namespace NeedleProject\FileIo\Content;
9
10
use NeedleProject\FileIo\Exception\ContentException;
11
12
/**
13
 * Class JsonContent
14
 *
15
 * @package NeedleProject\FileIo\Content
16
 * @author Adrian Tilita <[email protected]>
17
 * @copyright 2017 Adrian Tilita
18
 * @license https://opensource.org/licenses/MIT MIT Licence
19
 */
20
class JsonContent extends Content implements ContentInterface
21
{
22
    /**
23
     * Return the content as an array
24
     *
25
     * @return array
26
     * @throws \NeedleProject\FileIo\Exception\ContentException
27
     */
28 3 View Code Duplication
    public function getArray(): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30 3
        $content = json_decode($this->get(), true);
31 3
        if (json_last_error() !== JSON_ERROR_NONE) {
32 2
            throw new ContentException(
33 2
                sprintf("Could not decode content, got %s", json_last_error_msg())
34
            );
35
        }
36 1
        return $content;
37
    }
38
39
    /**
40
     * @return \stdClass
41
     * @throws \NeedleProject\FileIo\Exception\ContentException
42
     */
43 3 View Code Duplication
    public function getObject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45 3
        $content = json_decode($this->get());
46 3
        if (json_last_error() !== JSON_ERROR_NONE) {
47 2
            throw new ContentException(
48 2
                sprintf("Could not decode content, got %s", json_last_error_msg())
49
            );
50
        }
51 1
        return $content;
52
    }
53
}
54