Completed
Push — 2.0 ( 95bb32...281022 )
by Mark
8s
created

PurchaseService::getCreditCard()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
use Omnipay\Common\CreditCard;
4
use Omnipay\Common\Message\ResponseInterface;
5
6
class PurchaseService extends PaymentService
7
{
8
9
	/**
10
	 * Attempt to make a payment.
11
	 *
12
	 * @param  array $data returnUrl/cancelUrl + customer creditcard and billing/shipping details.
13
	 * 	Some keys (e.g. "amount") are overwritten with data from the associated {@link $payment}.
14
	 *  If this array is constructed from user data (e.g. a form submission), please take care
15
	 *  to whitelist accepted fields, in order to ensure sensitive gateway parameters like "freeShipping" can't be set.
16
	 *  If using {@link Form->getData()}, only fields which exist in the form are returned,
17
	 *  effectively whitelisting against arbitrary user input.
18
	 * @return ResponseInterface omnipay's response class, specific to the chosen gateway.
19
	 */
20
	public function purchase($data = array()) {
0 ignored issues
show
Complexity introduced by
This operation has 1200 execution paths which exceeds the configured maximum of 200.

A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.

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

Loading history...
21
		if ($this->payment->Status !== "Created") {
0 ignored issues
show
Documentation introduced by
The property Status does not exist on object<Payment>. 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...
22
			return null; //could be handled better? send payment response?
23
		}
24
		if (!$this->payment->isInDB()) {
25
			$this->payment->write();
26
		}
27
		//update success/fail urls
28
		$this->update($data);
29
30
		//set the client IP address, if not already set
31
		if(!isset($data['clientIp'])){
32
			$data['clientIp'] = Controller::curr()->getRequest()->getIP();
33
		}
34
35
		$gatewaydata = array_merge($data, array(
36
			'amount' => (float) $this->payment->MoneyAmount,
0 ignored issues
show
Documentation introduced by
The property MoneyAmount does not exist on object<Payment>. 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...
37
			'currency' => $this->payment->MoneyCurrency,
0 ignored issues
show
Documentation introduced by
The property MoneyCurrency does not exist on object<Payment>. 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...
38
			//set all gateway return/cancel/notify urls to PaymentGatewayController endpoint
39
			'returnUrl' => $this->getEndpointURL("complete", $this->payment->Identifier),
0 ignored issues
show
Documentation introduced by
The property Identifier does not exist on object<Payment>. 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
			'cancelUrl' => $this->getEndpointURL("cancel", $this->payment->Identifier),
0 ignored issues
show
Documentation introduced by
The property Identifier does not exist on object<Payment>. 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...
41
			'notifyUrl' => $this->getEndpointURL("notify", $this->payment->Identifier)
0 ignored issues
show
Documentation introduced by
The property Identifier does not exist on object<Payment>. 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...
42
		));
43
44
        // Often, the shop will want to pass in a transaction ID (order #, etc), but if there's
45
        // not one we need to set it as Ominpay requires this.
46
		if(!isset($gatewaydata['transactionId'])){
47
			$gatewaydata['transactionId'] = $this->payment->Identifier;
0 ignored issues
show
Documentation introduced by
The property Identifier 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...
48
		}
49
50
        // We only look for a card if we aren't already provided with a token
51
        // Increasingly we can expect tokens or nonce's to be more common (e.g. Stripe and Braintree)
52
        $tokenKey = Payment::config()->token_key ?: 'token';
53
        if (empty($gatewaydata[$tokenKey])) {
54
            $gatewaydata['card'] = $this->getCreditCard($data);
55
        } elseif ($tokenKey !== 'token') {
56
            // some gateways (eg. braintree) use a different key but we need
57
            // to normalize that for omnipay
58
            $gatewaydata['token'] = $gatewaydata[$tokenKey];
59
            unset($gatewaydata[$tokenKey]);
60
        }
61
62
        $this->extend('onBeforePurchase', $gatewaydata);
63
        $request = $this->oGateway()->purchase($gatewaydata);
0 ignored issues
show
Bug introduced by
The method purchase() does not exist on Omnipay\Common\AbstractGateway. Did you maybe mean supportsCompletePurchase()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
64
        $this->extend('onAfterPurchase', $request);
65
66
        $message = $this->createMessage('PurchaseRequest', $request);
67
		$message->SuccessURL = $this->returnurl;
68
		$message->FailureURL = $this->cancelurl;
69
		$message->write();
70
71
		$gatewayresponse = $this->createGatewayResponse();
72
		try {
73
			$response = $this->response = $request->send();
74
            $this->extend('onAfterSendPurchase', $request, $response);
75
			$gatewayresponse->setOmnipayResponse($response);
76
			//update payment model
77
			if (GatewayInfo::isManual($this->payment->Gateway)) {
0 ignored issues
show
Documentation introduced by
The property Gateway does not exist on object<Payment>. 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...
78
				//initiate manual payment
79
				$this->createMessage('AuthorizedResponse', $response);
80
				$this->payment->Status = 'Authorized';
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...
81
				$this->payment->write();
82
				$gatewayresponse->setMessage("Manual payment authorised");
83 View Code Duplication
			} elseif ($response->isSuccessful()) {
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...
84
				//successful payment
85
				$this->createMessage('PurchasedResponse', $response);
86
				$this->payment->Status = 'Captured';
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...
87
				$gatewayresponse->setMessage("Payment successful");
88
				$this->payment->write();
89
				$this->payment->extend('onCaptured', $gatewayresponse);
90
			} elseif ($response->isRedirect()) {
91
				// redirect to off-site payment gateway
92
				$this->createMessage('PurchaseRedirectResponse', $response);
93
				$this->payment->Status = 'Authorized';
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...
94
				$this->payment->write();
95
				$gatewayresponse->setMessage("Redirecting to gateway");
96 View Code Duplication
			} else {
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...
97
				//handle error
98
				$this->createMessage('PurchaseError', $response);
99
				$gatewayresponse->setMessage(
100
					"Error (".$response->getCode()."): ".$response->getMessage()
101
				);
102
			}
103
		} catch (Omnipay\Common\Exception\OmnipayException $e) {
104
			$this->createMessage('PurchaseError', $e);
0 ignored issues
show
Documentation introduced by
$e is of type object<Omnipay\Common\Exception\OmnipayException>, but the function expects a array|string|object<Omni...<OmnipayException>|null.

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...
105
			$gatewayresponse->setMessage($e->getMessage());
106
		}
107
		$gatewayresponse->setRedirectURL($this->getRedirectURL());
108
109
		return $gatewayresponse;
110
	}
111
112
	/**
113
	 * Finalise this payment, after off-site external processing.
114
	 * This is ususally only called by PaymentGatewayController.
115
	 * @return GatewayResponse encapsulated response info
116
	 */
117
	public function completePurchase($data = array()) {
118
		$gatewayresponse = $this->createGatewayResponse();
119
120
		//set the client IP address, if not already set
121
		if(!isset($data['clientIp'])){
122
			$data['clientIp'] = Controller::curr()->getRequest()->getIP();
123
		}
124
125
		$gatewaydata = array_merge($data, array(
126
			'amount' => (float) $this->payment->MoneyAmount,
0 ignored issues
show
Documentation introduced by
The property MoneyAmount does not exist on object<Payment>. 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...
127
			'currency' => $this->payment->MoneyCurrency
0 ignored issues
show
Documentation introduced by
The property MoneyCurrency does not exist on object<Payment>. 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...
128
		));
129
130
		$this->payment->extend('onBeforeCompletePurchase', $gatewaydata);
131
        $request = $this->oGateway()->completePurchase($gatewaydata);
0 ignored issues
show
Bug introduced by
The method completePurchase() does not exist on Omnipay\Common\AbstractGateway. Did you maybe mean supportsCompletePurchase()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
132
        $this->payment->extend('onAfterCompletePurchase', $request);
133
134
        $this->createMessage('CompletePurchaseRequest', $request);
135
		$response = null;
136
		try {
137
			$response = $this->response = $request->send();
138
            $this->extend('onAfterSendCompletePurchase', $request, $response);
139
			$gatewayresponse->setOmnipayResponse($response);
140 View Code Duplication
			if ($response->isSuccessful()) {
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...
141
				$this->createMessage('PurchasedResponse', $response);
142
				$this->payment->Status = 'Captured';
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...
143
				$this->payment->write();
144
				$this->payment->extend('onCaptured', $gatewayresponse);
145
			} else {
146
				$this->createMessage('CompletePurchaseError', $response);
147
			}
148
		} catch (Omnipay\Common\Exception\OmnipayException $e) {
149
			$this->createMessage("CompletePurchaseError", $e);
0 ignored issues
show
Documentation introduced by
$e is of type object<Omnipay\Common\Exception\OmnipayException>, but the function expects a array|string|object<Omni...<OmnipayException>|null.

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...
150
		}
151
152
		return $gatewayresponse;
153
	}
154
155
	public function cancelPurchase() {
156
		//TODO: do lookup? / try to complete purchase?
157
		//TODO: omnipay void call
158
		$this->payment->Status = 'Void';
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...
159
		$this->payment->write();
160
		$this->createMessage('VoidRequest', array(
161
			"Message" => "The payment was cancelled."
162
		));
163
164
		//return response
165
	}
166
167
	/**
168
	 * @return \Omnipay\Common\CreditCard
169
	 */
170
	protected function getCreditCard($data) {
171
		return new CreditCard($data);
172
	}
173
174
}
175