FlashObjectDOD   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 76
Duplicated Lines 13.16 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 6
dl 10
loc 76
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A extraStatics() 0 11 1
A set_classes_with_flash() 0 4 1
A get_classes_with_flash() 0 4 1
A set_classes_without_flash() 0 4 1
A get_classes_without_flash() 0 4 1
B updateCMSFields() 10 21 9
A CreateFlashObject() 0 10 2
A FlashObjectData() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/*
3
    @ see http://code.google.com/p/swfobject/wiki/documentation
4
    @ see http://www.swffix.org/swfobject/generator/
5
*/
6
7
class FlashObjectDOD extends SiteTreeDecorator
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...
8
{
9
    public function extraStatics()
10
    {
11
        return array(
12
            'db' =>   array(
13
                "Title" => "Varchar(255)"
14
            ),
15
            'has_one' => array(
16
                "FlashFile" => "File"
17
            ),
18
        );
19
    }
20
21
    protected static $classes_with_flash = array();
22
    public static function set_classes_with_flash($v)
23
    {
24
        self::$classes_with_flash = $v;
25
    }
26
    public static function get_classes_with_flash()
27
    {
28
        return self::$classes_with_flash;
29
    }
30
31
    protected static $classes_without_flash = array();
32
    public static function set_classes_without_flash($v)
33
    {
34
        self::$classes_without_flash = $v;
35
    }
36
    public static function get_classes_without_flash()
37
    {
38
        return self::$classes_without_flash;
39
    }
40
41
    public function updateCMSFields(FieldSet &$fields)
42
    {
43
        if (! FlashObject::has_external_flash_file()) {
44
            $show = true;
45 View Code Duplication
            if (is_array(self::get_classes_with_flash()) && count(self::get_classes_with_flash())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
                if (!in_array($this->owner->ClassName, self::get_classes_with_flash())) {
47
                    $show = false;
48
                }
49
            }
50 View Code Duplication
            if (is_array(self::get_classes_without_flash()) && count(self::get_classes_without_flash())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
                if (in_array($this->owner->ClassName, self::get_classes_without_flash())) {
52
                    $show = false;
53
                }
54
            }
55
            if ($show) {
56
                $fields->addFieldToTab("Root.Content.FlashObject", new FileIFrameField('FlashFile', 'File'));
57
                $fields->addFieldToTab("Root.Content.FlashObject", new TextField('Title', 'Title'));
58
            }
59
        }
60
        return $fields;
61
    }
62
63
    public function CreateFlashObject()
64
    {
65
        if ($this->owner->FlashFileID) {
66
            $obj = new FlashObject();
67
            $flashFile = $this->owner->FlashFile();
68
            return $obj->CreateFlashObject($this->owner->Title, null, $flashFile->Filename);
69
        } else {
70
            return new DataObjectSet();
71
        }
72
    }
73
74
    /*
75
    legacy function
76
    */
77
78
    public function FlashObjectData()
79
    {
80
        return $this->CreateFlashObject();
81
    }
82
}
83