Passed
Push — master ( d2510c...ae806a )
by Joschi
02:27
created

AbstractCssRulesetCompilerService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 66
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A compile() 0 11 2
A compileBreakpoint() 0 2 1
1
<?php
2
3
/**
4
 * responsive-images-css
5
 *
6
 * @category   Jkphl
7
 * @package    Jkphl\Respimgcss
8
 * @subpackage Jkphl\Respimgcss\Domain\Service
9
 * @author     Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright  Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license    http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Jkphl\Respimgcss\Domain\Service;
38
39
use Jkphl\Respimgcss\Application\Contract\UnitLengthInterface;
40
use Jkphl\Respimgcss\Domain\Contract\CssRulesetCompilerServiceInterface;
41
use Jkphl\Respimgcss\Domain\Contract\CssRulesetInterface;
42
use Jkphl\Respimgcss\Domain\Contract\ImageCandidateSetInterface;
43
use Jkphl\Respimgcss\Domain\Contract\LengthInterface;
44
45
/**
46
 * Abstract CSS Ruleset compiler service
47
 *
48
 * @package    Jkphl\Respimgcss
49
 * @subpackage Jkphl\Respimgcss\Domain
50
 */
51
abstract class AbstractCssRulesetCompilerService implements CssRulesetCompilerServiceInterface
52
{
53
    /**
54
     * CSS Ruleset
55
     *
56
     * @var CssRulesetInterface
57
     */
58
    protected $cssRuleset;
59
    /**
60
     * Breakpoints
61
     *
62
     * @var UnitLengthInterface[]
63
     */
64
    protected $breakPoints;
65
    /**
66
     * Image candidates
67
     *
68
     * @var ImageCandidateSetInterface
69
     */
70
    protected $imageCandidates = null;
71
72
    /**
73
     * CSS Ruleset Compiler Service constructor
74
     *
75
     * @param CssRulesetInterface $cssRuleset             CSS Ruleset
76
     * @param UnitLengthInterface[] $breakPoints          Breakpoints
77
     * @param ImageCandidateSetInterface $imageCandidates Image candidates
78
     */
79 3
    public function __construct(
80
        CssRulesetInterface $cssRuleset,
81
        array $breakPoints,
82
        ImageCandidateSetInterface $imageCandidates
83
    ) {
84 3
        $this->cssRuleset      = $cssRuleset;
85 3
        $this->breakPoints     = $breakPoints;
86 3
        $this->imageCandidates = $imageCandidates;
87 3
    }
88
89
    /**
90
     * Compile a CSS ruleset based on the registered breakpoints, image candidates and a given density
91
     *
92
     * @param int $density Device display density
93
     *
94
     * @return CssRulesetInterface CSS ruleset
95
     */
96 1
    public function compile(int $density): CssRulesetInterface
97
    {
98
        // Compile the minimum size
99 1
        $this->compileBreakpoint($density, null);
100
101
        // Run through and compile for all breakpoints
102 1
        foreach ($this->breakPoints as $breakPoint) {
103 1
            $this->compileBreakpoint($density, $breakPoint);
104
        }
105
106 1
        return $this->cssRuleset;
107
    }
108
109
    /**
110
     * Compile the CSS rules for particular breakpoint, a given density and the registered image candidates
111
     *
112
     * @param int $density                Device display density
113
     * @param LengthInterface $breakpoint Breakpoint length (NULL = minimum size / no breakpoint)
114
     */
115 1
    protected function compileBreakpoint(int $density, LengthInterface $breakpoint = null): void
0 ignored issues
show
Unused Code introduced by
The parameter $density is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

115
    protected function compileBreakpoint(/** @scrutinizer ignore-unused */ int $density, LengthInterface $breakpoint = null): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $breakpoint is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

115
    protected function compileBreakpoint(int $density, /** @scrutinizer ignore-unused */ LengthInterface $breakpoint = null): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
116
    {
117
118
    }
119
}