Passed
Branch master (fdd4ed)
by Adrian Florin
02:21
created

ContentFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 2
crap 3
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
13
/**
14
 * Class ContentFactory
15
 *
16
 * @package NeedleProject\FileIo\Factory
17
 * @author Adrian Tilita <[email protected]>
18
 * @copyright 2017 Adrian Tilita
19
 * @license https://opensource.org/licenses/MIT MIT Licence
20
 */
21
class ContentFactory
22
{
23
    /**
24
     * @const string
25
     */
26
    const EXT_TXT = 'txt';
27
28
    /**
29
     * @const string
30
     */
31
    const EXT_JSON = 'json';
32
33
    /**
34
     * Create a ContentInterface based on the extension and string content
35
     * @param string $extension
36
     * @param string $content
37
     * @return \NeedleProject\FileIo\Content\ContentInterface
38
     */
39 4
    public function create(string $extension, string $content): ContentInterface
40
    {
41
        switch ($extension) {
42
            /**
43
             * Create JSON Content
44
             * @todo Actually create a JsonContent
0 ignored issues
show
Coding Style introduced by
Comment refers to a TODO task

This check looks TODO comments that have been left in the code.

``TODO``s show that something is left unfinished and should be attended to.

Loading history...
45
             */
46 4
            case static::EXT_JSON:
47 1
                return new Content($content);
48
                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...
49
            /**
50
             * Default TXT Content
51
             */
52 3
            case static::EXT_TXT:
53
            default:
54 3
                return new Content($content);
55
        }
56
    }
57
}
58