FluentSchemaExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 17
ccs 6
cts 6
cp 1
rs 10
c 3
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A onAfterFieldDefinition() 0 9 2
1
<?php
2
/**
3
 * Class FluentSchemaExtension|Firesphere\SolrFluent\Extensions\FluentSchemaExtension Add Fluent schema requirements
4
 *
5
 * @package Firesphere\Solr\Fluent
6
 * @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo
7
 * @copyright Copyright (c) 2018 - now() Firesphere & Sheepy
8
 */
9
10
namespace Firesphere\SolrFluent\Extensions;
11
12
use Firesphere\SolrSearch\Factories\SchemaFactory;
13
use SilverStripe\Core\Extension;
14
use SilverStripe\ORM\ArrayList;
15
use SilverStripe\ORM\DataList;
16
use TractorCow\Fluent\Model\Locale;
17
18
/**
19
 * Class \Firesphere\SolrFluent\Extensions\FluentSchemaExtension
20
 *
21
 * Update the schema with the appropriate locale fields
22
 *
23
 * @package Firesphere\Solr\Fluent
24
 * @property SchemaFactory|FluentSchemaExtension $owner
25
 */
26
class FluentSchemaExtension extends Extension
27
{
28
    /**
29
     * Add the locale fields
30
     *
31
     * @param ArrayList|DataList $data ArrayList to which the copy should be pushed
32
     * @param array $item Item that's going to be altered per locale
33
     */
34 1
    public function onAfterFieldDefinition($data, $item): void
35
    {
36
        // A locale can be null, those need to be skipped
37 1
        $locales = Locale::get()->exclude(['Locale' => null]);
38
39 1
        foreach ($locales as $locale) {
40 1
            $copy = $item;
41 1
            $copy['Field'] = sprintf('%s_%s', $item['Field'], $locale->Locale);
42 1
            $data->push($copy);
43
        }
44 1
    }
45
}
46