MigratePaymentTask   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 13 4
A migrationRequired() 0 3 1
A migrateRecord() 0 19 1
A classToGateway() 0 15 2
1
<?php
2
3
class MigratePaymentTask extends BuildTask{
4
5
	protected $title = "Migrate Payments";
6
	protected $description = "Update payment records from old SilverStripe payment modul. See ominpay README!";
7
	
8
	protected $count = 0;
9
10
	public function run($request) {
11
		$query = new SQLQuery("*", "Payment");
0 ignored issues
show
Documentation introduced by
'Payment' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The class SQLQuery has been deprecated with message: since version 4.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
12
		foreach($query->execute() as $record){
13
			if($this->migrationRequired($record)){
14
				$this->migrateRecord($record);
15
			}
16
		}
17
		if($this->count > 0){
18
			echo "Successfully migrated $this->count payments";
19
		}else {
20
			echo "No migration needed";
21
		}
22
	}
23
24
	protected function migrationRequired($record) {
25
		return $record['ClassName'] !== "Payment";
26
	}
27
28
	protected function migrateRecord($record) {
29
		$payment = new Payment($record);
30
		$payment->Status = "Created";
0 ignored issues
show
Documentation introduced by
The property Status does not exist on object<Payment>. 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...
31
		$payment->ClassName = "Payment";
32
		$payment->MoneyAmount = $record['AmountAmount'];
0 ignored issues
show
Documentation introduced by
The property MoneyAmount does not exist on object<Payment>. 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...
33
		$payment->MoneyCurrency = $record['AmountCurrency'];
0 ignored issues
show
Documentation introduced by
The property MoneyCurrency does not exist on object<Payment>. 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...
34
		
35
		$payment->Gateway = $this->classToGateway($record['ClassName']);
0 ignored issues
show
Documentation introduced by
The property Gateway does not exist on object<Payment>. 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
		$statusmap = array(
37
			'Incomplete' => 'Created',
38
			'Success' => 'Captured',
39
			'Failure' => 'Void',
40
			'Pending' => 'Authorized',
41
			'' => 'Created'
42
		);
43
		$payment->Status = $statusmap[$record['Status']];
0 ignored issues
show
Documentation introduced by
The property Status does not exist on object<Payment>. 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...
44
		$payment->write();
45
		$this->count++;
46
	}
47
48
	protected function classToGateway($classname) {
49
		$gatewaymap = array(
50
			"ChequePayment" => "Manual",
51
			"DPSPayment" => "PaymentExpress_PxPay",
52
			"EwayXMLPayment" => "Eway_Rapid",
53
			"PayPalExpressCheckoutPayment" => "PayPal_Express",
54
			"PaystationHostedPayment" => "Paystation_Hosted",
55
			"WorldpayPayment" => "WorldPay"
56
		);
57
		if(isset($gatewaymap[$classname])){
58
			return $gatewaymap[$classname];
59
		}
60
61
		return $classname;
62
	}
63
64
}