Completed
Push — master ( 4d43de...d186d6 )
by Joram van den
04:11
created

App::__bootstrap()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 3
eloc 9
nc 2
nop 0
1
<?php
2
3
class App extends Ajde_Object_Singleton implements Ajde_BootstrapInterface
4
{
5
    public static function getInstance()
6
    {
7
        static $instance;
8
9
        return $instance === null ? $instance = new self : $instance;
10
    }
11
12
    public function __bootstrap()
13
    {
14
        \Nabble\SemaltBlocker\Blocker::protect();
15
16
        Ajde_Event::register('TransactionModel', 'onPaid', [$this, 'onTransactionPaid']);
17
        Ajde_Event::register('TransactionModel', 'onCreate', [$this, 'onTransactionCreated']);
18
19
        if (UserModel::isTester() || UserModel::isAdmin()) {
20
            $providers = Config::get('transactionProviders');
21
            $providers[] = 'test';
22
            Config::set('transactionProviders', $providers);
23
        }
24
25
        return true;
26
    }
27
28
    public function onTransactionPaid(TransactionModel $transaction)
29
    {
30
        /** @var TransactionItemModel $item */
31
        foreach ($transaction->getItems() as $item) {
32
            $entity = $item->getEntity();
33
            $qty = $item->qty;
34
35
            if ($entity instanceof ProductModel) {
36
                $entity->stock = $entity->stock - $qty;
0 ignored issues
show
Documentation introduced by
The property stock does not exist on object<ProductModel>. 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...
Documentation introduced by
The property stock does not exist on object<ProductModel>. 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
                $entity->save();
38
            }
39
        }
40
    }
41
42
    public function onTransactionCreated(TransactionModel $transaction)
43
    {
44
        $transaction->shipment_country = 'Nederland';
0 ignored issues
show
Documentation introduced by
The property shipment_country does not exist on object<TransactionModel>. 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...
45
    }
46
}
47