DMSDocumentAddExistingField   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 5
dl 0
loc 73
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
A setRecord() 0 5 1
B getRecord() 0 12 9
A FieldHolder() 0 4 1
A Field() 0 8 1
A setUseFieldClass() 0 5 1
1
<?php
2
3
class DMSDocumentAddExistingField extends CompositeField
4
{
5
    public $useFieldContext = true;
6
7
    public function __construct($name, $title = null)
8
    {
9
        $this->name = $name;
10
        $this->title = ($title === null) ? $name : $title;
11
12
        parent::__construct(
13
            new TreeDropdownField(
14
                'PageSelector',
15
                'Add from another page',
16
                'SiteTree',
17
                'ID',
18
                'TitleWithNumberOfDocuments'
19
            )
20
        );
21
    }
22
23
    /**
24
     * Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File)
25
     * @param DataObject $record
26
     */
27
    public function setRecord($record)
28
    {
29
        $this->record = $record;
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<DMSDocumentAddExistingField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
30
        return $this;
31
    }
32
    /**
33
     * Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it
34
     * will use Form->getRecord() or Form->Controller()->data()
35
     * @return DataObject
36
     */
37
    public function getRecord()
38
    {
39
        if (!$this->record && $this->form) {
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<DMSDocumentAddExistingField>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
40
            if ($this->form->getRecord() && is_a($this->form->getRecord(), 'DataObject')) {
41
                $this->record = $this->form->getRecord();
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<DMSDocumentAddExistingField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
42
            } elseif ($this->form->Controller() && $this->form->Controller()->hasMethod('data')
0 ignored issues
show
Deprecated Code introduced by
The method Form::Controller() has been deprecated with message: 4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
43
                    && $this->form->Controller()->data() && is_a($this->form->Controller()->data(), 'DataObject')) {
0 ignored issues
show
Deprecated Code introduced by
The method Form::Controller() has been deprecated with message: 4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
44
                $this->record = $this->form->Controller()->data();
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<DMSDocumentAddExistingField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Deprecated Code introduced by
The method Form::Controller() has been deprecated with message: 4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
45
            }
46
        }
47
        return $this->record;
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<DMSDocumentAddExistingField>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
48
    }
49
50
    public function FieldHolder($properties = array())
51
    {
52
        return $this->Field($properties);
53
    }
54
55
    public function Field($properties = array())
56
    {
57
        Requirements::javascript(DMS_DIR . '/javascript/DMSDocumentAddExistingField.js');
58
        Requirements::javascript(DMS_DIR . '/javascript/DocumentHtmlEditorFieldToolbar.js');
59
        Requirements::css(DMS_DIR . '/dist/css/cmsbundle.css');
60
61
        return $this->renderWith('DMSDocumentAddExistingField');
62
    }
63
64
    /**
65
     * Sets or unsets the use of the "field" class in the template. The "field" class adds Javascript behaviour
66
     * that causes unwelcome hiding side-effects when this Field is used within the link editor pop-up
67
     *
68
     * @return $this
69
     */
70
    public function setUseFieldClass($use = false)
71
    {
72
        $this->useFieldContext = $use;
73
        return $this;
74
    }
75
}
76