Passed
Push — master ( 3764eb...eb004c )
by Adrian Florin
04:02
created

ContentFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 36
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 17 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
use NeedleProject\FileIo\Content\JsonContent;
13
14
/**
15
 * Class ContentFactory
16
 *
17
 * @package NeedleProject\FileIo\Factory
18
 * @author Adrian Tilita <[email protected]>
19
 * @copyright 2017 Adrian Tilita
20
 * @license https://opensource.org/licenses/MIT MIT Licence
21
 */
22
class ContentFactory
23
{
24
    /**
25
     * @const string
26
     */
27
    const EXT_TXT = 'txt';
28
29
    /**
30
     * @const string
31
     */
32
    const EXT_JSON = 'json';
33
34
    /**
35
     * Create a ContentInterface based on the extension and string content
36
     * @param string $extension
37
     * @param string $content
38
     * @return \NeedleProject\FileIo\Content\ContentInterface
39
     */
40
    public function create(string $extension, string $content): ContentInterface
41
    {
42
        switch ($extension) {
43
            /**
44
             * Create JSON Content
45
             */
46
            case static::EXT_JSON:
47
                return new JsonContent($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
            case static::EXT_TXT:
53
            default:
54
                return new Content($content);
55
        }
56
    }
57
}
58