PaymentMessage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 36
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 3 1
A getTitle() 0 3 1
A onBeforeWrite() 0 7 3
1
<?php
2
3
/**
4
 * Base class for logging messages, transactions etc associated with a payment.
5
 *
6
 * @package payment
7
 */
8
class PaymentMessage extends DataObject{
9
10
	private static $db = array(
11
		//Created
12
		"Message" => "Varchar(255)",
13
		"ClientIp" => "Varchar(39)"
14
	);
15
16
	private static $has_one = array(
17
		"Payment" => "Payment",
18
		"User" => "Member" //currently logged in user, if appliciable
19
	);
20
21
	private static $summary_fields = array(
22
		'i18n_singular_name' => "Type",
23
		'Message' => "Message",
24
		'User.Name' => "User"
25
	);
26
27
	public function getCMSFields() {
28
		return parent::getCMSFields()->makeReadOnly();
29
	}
30
31
	public function onBeforeWrite() {
32
		parent::onBeforeWrite();
33
		//automatically set the current user id for new payment messages
34
		if (!$this->UserID && !$this->isInDB()) {
0 ignored issues
show
Documentation introduced by
The property UserID does not exist on object<PaymentMessage>. 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...
35
			$this->UserID = Member::currentUserID();
0 ignored issues
show
Documentation introduced by
The property UserID does not exist on object<PaymentMessage>. 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...
36
		}
37
	}
38
39
	function getTitle(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
40
		return $this->i18n_singular_name();
41
	}
42
43
}
44