Completed
Push — master ( 5bd6a5...9e9952 )
by Terzi
08:06
created

Mutable::create()   B

Complexity

Conditions 8
Paths 25

Size

Total Lines 44
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 44
rs 8.4444
c 0
b 0
f 0
cc 8
nc 25
nop 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B Mutable::editors() 0 16 7
1
<?php
2
3
namespace Terranet\Administrator\Form\Collection;
4
5
use Terranet\Administrator\Collection\Mutable as BaseMutableCollection;
6
use Terranet\Administrator\Columns\MediaElement;
0 ignored issues
show
Bug introduced by
The type Terranet\Administrator\Columns\MediaElement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Terranet\Administrator\Exception;
8
use Terranet\Administrator\Field\Textarea;
9
use Terranet\Administrator\Form\FormElement;
0 ignored issues
show
Bug introduced by
The type Terranet\Administrator\Form\FormElement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Terranet\Administrator\Form\FormSection;
0 ignored issues
show
Bug introduced by
The type Terranet\Administrator\Form\FormSection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Terranet\Administrator\Form\InputFactory;
0 ignored issues
show
Bug introduced by
The type Terranet\Administrator\Form\InputFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
class Mutable extends BaseMutableCollection
14
{
15
    /**
16
     * Whether the collection has active editor of specific type.
17
     *
18
     * @param $editor
19
     *
20
     * @throws Exception
21
     *
22
     * @return bool
23
     */
24
    public function hasEditors($editor)
25
    {
26
        $this->validateEditor($editor);
27
28
        return (bool) $this->filter(function ($field) use ($editor) {
29
            return $field instanceof Textarea && $field->editorEnabled($editor);
30
        })->count();
31
    }
32
33
    /**
34
     * Set rich editors.
35
     *
36
     * @param mixed string|array $fields
37
     */
38
    public function editors($fields, string $editor = null)
39
    {
40
        if (is_array($fields)) {
41
            foreach ($fields as $field => $editor) {
42
                $this->editors($field, $editor);
43
            }
44
        } elseif (is_string($fields) && $editor) {
45
            $item = $this->find($fields);
46
            if ($item instanceof Textarea) {
47
                if (method_exists($item, $editor)) {
48
                    $item->$editor();
49
                }
50
            }
51
        }
52
53
        return $this;
54
    }
55
56
    /**
57
     * Set fields descriptions.
58
     *
59
     * @param mixed string|array $fields
60
     */
61
    public function hints($fields, string $hint = null)
62
    {
63
        if (is_array($fields)) {
64
            foreach ($fields as $field => $hint) {
65
                $this->hints($field, $hint);
66
            }
67
        } elseif (is_string($fields) && $hint) {
68
            $item = $this->find($fields);
69
            $item->setDescription($hint);
70
        }
71
72
        return $this;
73
    }
74
75
    /**
76
     * @param $editor
77
     *
78
     * @throws Exception
79
     */
80
    protected function validateEditor($editor)
81
    {
82
        if (!in_array($editor, ['ckeditor', 'tinymce', 'medium', 'markdown'], true)) {
83
            throw new Exception(sprintf('Unknown editor %s', $editor));
84
        }
85
    }
86
}
87