1 | <?php |
||||||
2 | |||||||
3 | namespace ByTIC\Payments\Models\Transactions; |
||||||
4 | |||||||
5 | use ByTIC\Payments\Models\AbstractModels\HasPaymentMethod\HasPaymentMethodRepository; |
||||||
6 | use ByTIC\Payments\Models\AbstractModels\HasToken\HasTokenRepository; |
||||||
7 | use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait; |
||||||
8 | use ByTIC\Payments\Models\Purchases\Purchase; |
||||||
9 | use ByTIC\Payments\Utility\PaymentsModels; |
||||||
10 | use Nip\MailModule\Models\EmailsTable\EmailTrait; |
||||||
0 ignored issues
–
show
|
|||||||
11 | use Nip\Records\AbstractModels\Record; |
||||||
12 | use Nip\Records\EventManager\Events\Event; |
||||||
13 | |||||||
14 | /** |
||||||
15 | * Trait TransactionsTrait |
||||||
16 | * @package ByTIC\Payments\Models\Transactions |
||||||
17 | * |
||||||
18 | * @method TransactionTrait getNew |
||||||
19 | */ |
||||||
20 | trait TransactionsTrait |
||||||
21 | { |
||||||
22 | use \ByTIC\Models\SmartProperties\RecordsTraits\HasStatus\RecordsTrait; |
||||||
23 | use HasTokenRepository; |
||||||
24 | use HasPaymentMethodRepository; |
||||||
25 | |||||||
26 | public function bootTransactionsTrait() |
||||||
27 | { |
||||||
28 | static::creating(function (Event $event) { |
||||||
29 | |||||||
30 | /** @var EmailTrait|\Nip\Records\Record $record */ |
||||||
31 | $record = $event->getRecord(); |
||||||
32 | |||||||
33 | $record->setIf('metadata', '{}', function () use ($record) { |
||||||
34 | return count($record->metadata) < 1; |
||||||
0 ignored issues
–
show
It seems like
$record->metadata can also be of type null ; however, parameter $value of count() does only seem to accept Countable|array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
35 | }); |
||||||
36 | }); |
||||||
37 | } |
||||||
38 | |||||||
39 | /** |
||||||
40 | * @param Purchase|IsPurchasableModelTrait $purchase |
||||||
41 | * @return TransactionTrait |
||||||
42 | */ |
||||||
43 | public function findOrCreateForPurchase($purchase) |
||||||
44 | { |
||||||
45 | $transaction = $this->findForPurchase($purchase); |
||||||
46 | if ($transaction instanceof Record) { |
||||||
47 | return $transaction; |
||||||
0 ignored issues
–
show
|
|||||||
48 | } |
||||||
49 | return $this->createForPurchase($purchase); |
||||||
50 | } |
||||||
51 | |||||||
52 | /** |
||||||
53 | * @param Purchase|IsPurchasableModelTrait $purchase |
||||||
54 | * @return TransactionTrait|null |
||||||
55 | */ |
||||||
56 | public function findForPurchase($purchase) |
||||||
57 | { |
||||||
58 | return $this->findOneByField('id_purchase', $purchase->id); |
||||||
0 ignored issues
–
show
The method
findOneByField() does not exist on ByTIC\Payments\Models\Tr...tions\TransactionsTrait . Did you maybe mean findOneByQuery() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
59 | } |
||||||
60 | |||||||
61 | /** |
||||||
62 | * @return string |
||||||
63 | */ |
||||||
64 | public function getStatusItemsRootNamespace() |
||||||
65 | { |
||||||
66 | return '\ByTIC\Payments\Models\Transactions\Statuses\\'; |
||||||
67 | } |
||||||
68 | |||||||
69 | /** |
||||||
70 | * @return string |
||||||
71 | */ |
||||||
72 | public function getStatusItemsDirectory() |
||||||
73 | { |
||||||
74 | return __DIR__ . DIRECTORY_SEPARATOR . 'Statuses'; |
||||||
75 | } |
||||||
76 | |||||||
77 | /** |
||||||
78 | * @param Purchase|IsPurchasableModelTrait $purchase |
||||||
79 | * @return TransactionTrait |
||||||
80 | */ |
||||||
81 | protected function createForPurchase($purchase) |
||||||
82 | { |
||||||
83 | $transaction = $this->getNew(); |
||||||
84 | $transaction->populateFromPayment($purchase); |
||||||
85 | $transaction->populateFromGateway($purchase->getPaymentMethod()->getType()->getGateway()); |
||||||
86 | $transaction->insert(); |
||||||
0 ignored issues
–
show
It seems like
insert() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
87 | return $transaction; |
||||||
88 | } |
||||||
89 | |||||||
90 | protected function initRelations() |
||||||
91 | { |
||||||
92 | parent::initRelations(); |
||||||
93 | $this->initRelationsCommon(); |
||||||
94 | } |
||||||
95 | |||||||
96 | protected function initRelationsCommon() |
||||||
97 | { |
||||||
98 | $this->initRelationsPurchase(); |
||||||
99 | $this->initRelationsPaymentMethod(); |
||||||
100 | $this->initRelationsSubscription(); |
||||||
101 | $this->initRelationsToken(); |
||||||
102 | } |
||||||
103 | |||||||
104 | protected function initRelationsPurchase() |
||||||
105 | { |
||||||
106 | $this->belongsTo('Purchase', ['class' => get_class(PaymentsModels::purchases()), 'fk' => 'id_purchase']); |
||||||
0 ignored issues
–
show
It seems like
belongsTo() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
107 | } |
||||||
108 | |||||||
109 | protected function initRelationsSubscription() |
||||||
110 | { |
||||||
111 | $this->belongsTo('Subscription', ['class' => get_class(PaymentsModels::subscriptions())]); |
||||||
112 | } |
||||||
113 | |||||||
114 | /** |
||||||
115 | * @param array $params |
||||||
116 | */ |
||||||
117 | protected function injectParams(&$params = []) |
||||||
118 | { |
||||||
119 | $params['order'][] = ['created', 'desc']; |
||||||
120 | |||||||
121 | parent::injectParams($params); |
||||||
122 | } |
||||||
123 | |||||||
124 | /** |
||||||
125 | * @return mixed|\Nip\Config\Config |
||||||
126 | * @throws \Exception |
||||||
127 | */ |
||||||
128 | protected function generateTable() |
||||||
129 | { |
||||||
130 | return config('payments.tables.transactions', \ByTIC\Payments\Models\Transactions\Transactions::TABLE); |
||||||
131 | } |
||||||
132 | } |
||||||
133 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths