Builder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 10 2
A buildRuleset() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the bisarca/robots-txt package.
5
 *
6
 * (c) Emanuele Minotto <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bisarca\RobotsTxt;
13
14
/**
15
 * Robots.txt file builder/serializer.
16
 */
17
class Builder
18
{
19
    /**
20
     * Builds the robots.txt file content.
21
     *
22
     * @param Rulesets $rulesets Required rulesets
23
     *
24
     * @return string
25
     */
26
    public function build(Rulesets $rulesets): string
27
    {
28
        $output = '';
29
30
        foreach ($rulesets as $ruleset) {
31
            $output .= $this->buildRuleset($ruleset).PHP_EOL;
32
        }
33
34
        return rtrim($output, PHP_EOL).PHP_EOL;
35
    }
36
37
    /**
38
     * Builds a single robots.txt' set of directives (ruleset).
39
     *
40
     * @param Ruleset $ruleset Required ruleset
41
     *
42
     * @return string
43
     */
44
    private function buildRuleset(Ruleset $ruleset): string
45
    {
46
        $output = '';
47
48
        foreach ($ruleset as $directive) {
49
            $output .= $directive.PHP_EOL;
50
        }
51
52
        return $output;
53
    }
54
}
55