Completed
Push — master ( 6dd3a0...ec39b9 )
by Níckolas Daniel
05:32
created

RobotsTxtStringBuilder   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 16
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 22 1
1
<?php
2
3
namespace PODEntender\Domain\Model\FileProcessing\RobotsTxt;
4
5
class RobotsTxtStringBuilder
6
{
7
    public function build(RobotsTxt $robot): string
8
    {
9
        $robotsTxt = ['Sitemap: ' . $robot->sitemap()];
10
        $rules = $robot->ruleSetCollection()
11
            ->map(function (RulesSet $rule) {
12
                return array_merge(
13
                    [
14
                        '',
15
                        'User-Agent: ' . $rule->userAgent(),
16
                    ],
17
                    array_map(function (string $string) {
18
                        return "Allow: $string";
19
                    }, $rule->allowRules()),
20
                    array_map(function (string $string) {
21
                        return "Disallow: $string";
22
                    }, $rule->disallowRules())
23
                );
24
            })
25
            ->flatten()
26
            ->toArray();
27
28
        return implode(PHP_EOL, array_merge($robotsTxt, $rules));
29
    }
30
}
31