Completed
Push — master ( 9d55e1...d2116f )
by Dmitry
02:49
created

src/views/pay/deposit-form.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use hiqdev\paymenticons\yii2\PaymentIconsAsset;
4
use yii\helpers\Html;
5
use yii\widgets\ActiveForm;
6
7
/**
8
 * @var \yii\web\View $this
9
 * @var \hiqdev\php\merchant\AbstractMerchant[] $availableMerchants
10
 */
11
12
$this->title = Yii::t('merchant', 'Account recharging');
13
$this->params['breadcrumbs'][] = $this->title;
14
PaymentIconsAsset::register(Yii::$app->getView());
15
16
$merchantNames = [];
17
foreach ($availableMerchants as $merchant) {
18
    if (isset($merchantNames[$merchant->getGateway()])) {
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class hiqdev\php\merchant\AbstractMerchant as the method getGateway() does only exist in the following sub-classes of hiqdev\php\merchant\AbstractMerchant: hiqdev\php\merchant\OmnipayMerchant, hiqdev\php\merchant\interkassa\OmnipayMerchant, hiqdev\php\merchant\paypal\OmnipayMerchant, hiqdev\php\merchant\webmoney\OmnipayMerchant. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
19
        continue;
20
    }
21
    $merchantNames[$merchant->getGateway()] = $merchant->getLabel();
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class hiqdev\php\merchant\AbstractMerchant as the method getGateway() does only exist in the following sub-classes of hiqdev\php\merchant\AbstractMerchant: hiqdev\php\merchant\OmnipayMerchant, hiqdev\php\merchant\interkassa\OmnipayMerchant, hiqdev\php\merchant\paypal\OmnipayMerchant, hiqdev\php\merchant\webmoney\OmnipayMerchant. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
22
}
23
24
?>
25
26
<div class="row">
27
    <div class="col-md-offset-3 col-md-6">
28
        <div class="box">
29
            <div class="box-header with-border">
30
                <h3 class="box-title"><?= $this->title ?></h3>
31
            </div>
32
            <div class="box-body">
33
                <?php $form = ActiveForm::begin() ?>
34
                <?php foreach ($model->attributes() as $attr): ?>
35
                    <?= $form->field($model, $attr) ?>
36
                <?php endforeach ?>
37
                <?= Html::submitButton(Yii::t('merchant', 'Proceed'), ['class' => 'btn btn-primary']) ?>
38
                <?php $form->end() ?>
39
                <div class="text-muted">
40
                    <hr>
41
                    <?= Yii::t('merchant', 'We support fully automatic account depositing with the following payment systems: {merchants}', [
42
                        'merchants' => implode(',&nbsp; ', array_values($merchantNames))
43
                    ]) ?>
44
                    <br>
45
                    <br>
46
                    <?php foreach ($merchantNames as $name => $label) : ?>
47
                        <i class="pi pi-xs pi-<?= $name ?>"></i>
48
                    <?php endforeach; ?>
49
                </div>
50
            </div>
51
        </div>
52
    </div>
53
    <div class="col-md-offset-3 col-md-6">
54
        <div class="callout callout-warning">
55
            <h4><?= Yii::t('merchant', 'Important information') ?></h4>
56
            <p><?= Yii::t('merchant', 'Remember to return to the site after successful payment!') ?></p>
57
        </div>
58
    </div>
59
</div>
60