1 | <?php declare(strict_types=1); |
||||||||||||
2 | |||||||||||||
3 | namespace OfxParser\Ofx; |
||||||||||||
4 | |||||||||||||
5 | use SimpleXMLElement; |
||||||||||||
6 | use OfxParser\Ofx; |
||||||||||||
7 | use OfxParser\Utils; |
||||||||||||
8 | use OfxParser\Entities\Statement; |
||||||||||||
9 | use OfxParser\Entities\Investment\Account as InvestmentAccount; |
||||||||||||
10 | use OfxParser\Entities\Investment\Transaction\Banking; |
||||||||||||
11 | use OfxParser\Entities\Investment\Transaction\BuyMutualFund; |
||||||||||||
12 | use OfxParser\Entities\Investment\Transaction\BuySecurity; |
||||||||||||
13 | use OfxParser\Entities\Investment\Transaction\BuyStock; |
||||||||||||
14 | use OfxParser\Entities\Investment\Transaction\Income; |
||||||||||||
15 | use OfxParser\Entities\Investment\Transaction\Reinvest; |
||||||||||||
16 | use OfxParser\Entities\Investment\Transaction\SellMutualFund; |
||||||||||||
17 | |||||||||||||
18 | final class Investment extends Ofx |
||||||||||||
19 | { |
||||||||||||
20 | /** |
||||||||||||
21 | * @param SimpleXMLElement $xml |
||||||||||||
22 | * @throws \Exception |
||||||||||||
23 | */ |
||||||||||||
24 | public function __construct(SimpleXMLElement $xml) |
||||||||||||
25 | { |
||||||||||||
26 | $this->signOn = $this->buildSignOn($xml->SIGNONMSGSRSV1->SONRS); |
||||||||||||
27 | |||||||||||||
28 | if (property_exists($xml, 'INVSTMTMSGSRSV1') && $xml->INVSTMTMSGSRSV1 !== null) { |
||||||||||||
29 | $this->bankAccounts = $this->buildAccounts($xml); |
||||||||||||
30 | } |
||||||||||||
31 | |||||||||||||
32 | // Set a helper if only one bank account |
||||||||||||
33 | if (count($this->bankAccounts) === 1) { |
||||||||||||
34 | $this->bankAccount = $this->bankAccounts[0]; |
||||||||||||
0 ignored issues
–
show
|
|||||||||||||
35 | } |
||||||||||||
36 | } |
||||||||||||
37 | |||||||||||||
38 | /** |
||||||||||||
39 | * @param SimpleXMLElement $xml |
||||||||||||
40 | * @return array Array of InvestmentAccount enities |
||||||||||||
41 | * @throws \Exception |
||||||||||||
42 | */ |
||||||||||||
43 | protected function buildAccounts(SimpleXMLElement $xml): array |
||||||||||||
44 | { |
||||||||||||
45 | // Loop through the bank accounts |
||||||||||||
46 | $accounts = []; |
||||||||||||
47 | foreach ($xml->INVSTMTMSGSRSV1->INVSTMTTRNRS as $accountStatement) { |
||||||||||||
48 | foreach ($accountStatement->INVSTMTRS as $statementResponse) { |
||||||||||||
49 | $accounts[] = $this->buildAccount($accountStatement->TRNUID, $statementResponse); |
||||||||||||
0 ignored issues
–
show
It seems like
$statementResponse can also be of type null ; however, parameter $statementResponse of OfxParser\Ofx\Investment::buildAccount() does only seem to accept SimpleXMLElement , 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
![]() |
|||||||||||||
50 | } |
||||||||||||
51 | } |
||||||||||||
52 | return $accounts; |
||||||||||||
53 | } |
||||||||||||
54 | |||||||||||||
55 | /** |
||||||||||||
56 | * @param string $transactionUid |
||||||||||||
57 | * @param SimpleXMLElement $statementResponse |
||||||||||||
58 | * @return InvestmentAccount |
||||||||||||
59 | * @throws \Exception |
||||||||||||
60 | */ |
||||||||||||
61 | protected function buildAccount(?SimpleXMLElement $transactionUid, SimpleXMLElement $statementResponse): InvestmentAccount |
||||||||||||
62 | { |
||||||||||||
63 | $account = new InvestmentAccount(); |
||||||||||||
64 | $account->transactionUid = (string) $transactionUid; |
||||||||||||
65 | $account->brokerId = (string) $statementResponse->INVACCTFROM->BROKERID; |
||||||||||||
66 | $account->accountNumber = (string) $statementResponse->INVACCTFROM->ACCTID; |
||||||||||||
67 | |||||||||||||
68 | $account->statement = new Statement(); |
||||||||||||
0 ignored issues
–
show
It seems like
new OfxParser\Entities\Statement() of type OfxParser\Entities\Statement is incompatible with the declared type OfxParser\Entities\Investment\Statement of property $statement .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||||||||||||
69 | $account->statement->currency = (string) $statementResponse->CURDEF; |
||||||||||||
70 | |||||||||||||
71 | $account->statement->startDate = Utils::createDateTimeFromStr( |
||||||||||||
72 | $statementResponse->INVTRANLIST->DTSTART |
||||||||||||
73 | ); |
||||||||||||
74 | |||||||||||||
75 | $account->statement->endDate = Utils::createDateTimeFromStr( |
||||||||||||
76 | $statementResponse->INVTRANLIST->DTEND |
||||||||||||
77 | ); |
||||||||||||
78 | |||||||||||||
79 | $account->statement->transactions = $this->buildTransactions( |
||||||||||||
80 | $statementResponse->INVTRANLIST->children() |
||||||||||||
81 | ); |
||||||||||||
82 | |||||||||||||
83 | return $account; |
||||||||||||
84 | } |
||||||||||||
85 | |||||||||||||
86 | /** |
||||||||||||
87 | * Processes multiple types of investment transactions, ignoring many |
||||||||||||
88 | * others. |
||||||||||||
89 | * |
||||||||||||
90 | * @param SimpleXMLElement $transactions |
||||||||||||
91 | * @throws \Exception |
||||||||||||
92 | * @return \OfxParser\Entities\Investment\Transaction\Banking[]|\OfxParser\Entities\Investment\Transaction\BuySecurity[]|\OfxParser\Entities\Investment\Transaction\Income[]|\OfxParser\Entities\Investment\Transaction\SellMutualFund[] |
||||||||||||
93 | */ |
||||||||||||
94 | protected function buildTransactions(SimpleXMLElement $transactions): array |
||||||||||||
95 | { |
||||||||||||
96 | $activity = []; |
||||||||||||
97 | |||||||||||||
98 | foreach ($transactions as $t) { |
||||||||||||
99 | $item = null; |
||||||||||||
100 | |||||||||||||
101 | switch ($t->getName()) { |
||||||||||||
0 ignored issues
–
show
The method
getName() does not exist on null .
(
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. ![]() |
|||||||||||||
102 | case 'BUYMF': |
||||||||||||
103 | $item = new BuyMutualFund(); |
||||||||||||
104 | break; |
||||||||||||
105 | case 'BUYOTHER': |
||||||||||||
106 | $item = new BuySecurity(); |
||||||||||||
107 | break; |
||||||||||||
108 | case 'BUYSTOCK': |
||||||||||||
109 | $item = new BuyStock(); |
||||||||||||
110 | break; |
||||||||||||
111 | case 'INCOME': |
||||||||||||
112 | $item = new Income(); |
||||||||||||
113 | break; |
||||||||||||
114 | case 'INVBANKTRAN': |
||||||||||||
115 | $item = new Banking(); |
||||||||||||
116 | break; |
||||||||||||
117 | case 'REINVEST': |
||||||||||||
118 | $item = new Reinvest(); |
||||||||||||
119 | break; |
||||||||||||
120 | case 'SELLMF': |
||||||||||||
121 | $item = new SellMutualFund(); |
||||||||||||
122 | break; |
||||||||||||
123 | case 'DTSTART': |
||||||||||||
124 | // already processed |
||||||||||||
125 | break; |
||||||||||||
126 | case 'DTEND': |
||||||||||||
127 | // already processed |
||||||||||||
128 | break; |
||||||||||||
129 | default: |
||||||||||||
130 | // Log: ignored node.... |
||||||||||||
131 | break; |
||||||||||||
132 | } |
||||||||||||
133 | |||||||||||||
134 | if (!is_null($item)) { |
||||||||||||
135 | $item->loadOfx($t); |
||||||||||||
0 ignored issues
–
show
It seems like
$t can also be of type null ; however, parameter $node of OfxParser\Entities\Inves...on\SellStock::loadOfx() does only seem to accept SimpleXMLElement , 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
![]() It seems like
$t can also be of type null ; however, parameter $node of OfxParser\Entities\Inves...\BuySecurity::loadOfx() does only seem to accept SimpleXMLElement , 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
![]() It seems like
$t can also be of type null ; however, parameter $node of OfxParser\Entities\Inves...ion\BuyStock::loadOfx() does only seem to accept SimpleXMLElement , 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
![]() It seems like
$t can also be of type null ; however, parameter $node of OfxParser\Entities\Inves...tion\Banking::loadOfx() does only seem to accept SimpleXMLElement , 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
![]() It seems like
$t can also be of type null ; however, parameter $node of OfxParser\Entities\Inves...ction\Income::loadOfx() does only seem to accept SimpleXMLElement , 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
![]() |
|||||||||||||
136 | $activity[] = $item; |
||||||||||||
137 | } |
||||||||||||
138 | } |
||||||||||||
139 | |||||||||||||
140 | return $activity; |
||||||||||||
141 | } |
||||||||||||
142 | } |
||||||||||||
143 |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.