ContentFactory::create()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 8.5125
c 0
b 0
f 0
cc 5
eloc 12
nc 5
nop 2
crap 5
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\Factory;
9
10
use NeedleProject\FileIo\Content\Content;
11
use NeedleProject\FileIo\Content\ContentInterface;
12
use NeedleProject\FileIo\Content\JsonContent;
13
use NeedleProject\FileIo\Content\YamlContent;
14
15
/**
16
 * Class ContentFactory
17
 *
18
 * @package NeedleProject\FileIo\Factory
19
 * @author Adrian Tilita <[email protected]>
20
 * @copyright 2017 Adrian Tilita
21
 * @license https://opensource.org/licenses/MIT MIT Licence
22
 */
23
class ContentFactory
24
{
25
    /**
26
     * @const string
27
     */
28
    const EXT_TXT = 'txt';
29
30
    /**
31
     * @const string
32
     */
33
    const EXT_JSON = 'json';
34
35
    /**
36
     * @const string
37
     */
38
    const EXT_YAML = 'yaml';
39
40
    /**
41
     * @const string
42
     */
43
    const EXT_YML = 'yml';
44
45
    /**
46
     * Create a ContentInterface based on the extension and string content
47
     * @param string $extension
48
     * @param string $content
49
     * @return \NeedleProject\FileIo\Content\ContentInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be null|Content?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
50
     */
51 8
    public function create($extension, $content)
52
    {
53
        switch ($extension) {
54
            /**
55
             * Create JSON Content
56
             */
57 8
            case static::EXT_JSON:
58 1
                return new JsonContent($content);
59
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
60
            /**
61
             * Create YAML Content
62
             */
63 7
            case static::EXT_YAML:
64 7
            case static::EXT_YML:
65 1
                return new YamlContent($content);
66
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
67
            /**
68
             * Default TXT Content
69
             */
70 6
            case static::EXT_TXT:
71
            default:
72 6
                return new Content($content);
73
        }
74
    }
75
}
76