Completed
Push — master ( e4ab2b...e8d46a )
by Franco
24s queued 18s
created

DMSTaxonomyTypeExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A requireDefaultRecords() 0 11 3
1
<?php
2
/**
3
 * Creates default taxonomy type records if they don't exist already
4
 */
5
class DMSTaxonomyTypeExtension extends DataExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    /**
8
     * Create default taxonomy type records. Add records via YAML configuration (see taxonomy.yml):
9
     *
10
     * <code>
11
     * DMSTaxonomyTypeExtension:
12
     *   default_records:
13
     *     - Document
14
     *     - PrivateDocument
15
     * </code>
16
     */
17
    public function requireDefaultRecords()
18
    {
19
        $records = (array) Config::inst()->get(get_class($this), 'default_records');
20
        foreach ($records as $name) {
21
            $type = TaxonomyType::get()->filter('Name', $name)->first();
22
            if (!$type) {
23
                $type = TaxonomyType::create(array('Name' => $name));
24
                $type->write();
25
            }
26
        }
27
    }
28
}
29