Conditions | 2 |
Paths | 2 |
Total Lines | 84 |
Code Lines | 69 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
13 | public function testParseInvestmentsXML() |
||
14 | { |
||
15 | $parser = new InvestmentParser(); |
||
16 | $ofx = $parser->loadFromFile(__DIR__ . '/../../fixtures/ofxdata-investments-xml.ofx'); |
||
17 | |||
18 | $account = reset($ofx->bankAccounts); |
||
19 | self::assertSame('TEST-UID-1', $account->transactionUid); |
||
20 | self::assertSame('vanguard.com', $account->brokerId); |
||
21 | self::assertSame('1234567890', $account->accountNumber); |
||
22 | |||
23 | // Check some transactions: |
||
24 | $expected = array( |
||
25 | '100100' => array( |
||
26 | 'tradeDate' => new \DateTime('2010-01-01'), |
||
27 | 'settlementDate' => new \DateTime('2010-01-02'), |
||
28 | 'securityId' => '122022322', |
||
29 | 'securityIdType' => 'CUSIP', |
||
30 | 'units' => '31.25', |
||
31 | 'unitPrice' => '32.0', |
||
32 | 'total' => '-1000.0', |
||
33 | 'buyType' => 'BUY', |
||
34 | 'actionCode' => 'BUYMF', |
||
35 | ), |
||
36 | '100200' => array( |
||
37 | 'tradeDate' => new \DateTime('2011-02-01'), |
||
38 | 'settlementDate' => new \DateTime('2011-02-03'), |
||
39 | 'securityId' => '355055155', |
||
40 | 'securityIdType' => 'CUSIP', |
||
41 | 'units' => '3.0', |
||
42 | 'unitPrice' => '181.96', |
||
43 | 'total' => '-545.88', |
||
44 | 'buyType' => 'BUY', |
||
45 | 'actionCode' => 'BUYSTOCK', |
||
46 | ), |
||
47 | '100300' => array( |
||
48 | 'tradeDate' => new \DateTime('2010-01-01'), |
||
49 | 'settlementDate' => new \DateTime('2010-01-01'), |
||
50 | 'securityId' => '122022322', |
||
51 | 'securityIdType' => 'CUSIP', |
||
52 | 'units' => '-1000.0', |
||
53 | 'unitPrice' => '1.0', |
||
54 | 'total' => '1000.0', |
||
55 | 'sellType' => 'SELL', |
||
56 | 'actionCode' => 'SELLMF', |
||
57 | ), |
||
58 | '200100' => array( |
||
59 | 'tradeDate' => new \DateTime('2011-02-01'), |
||
60 | 'settlementDate' => new \DateTime('2011-02-01'), |
||
61 | 'securityId' => '822722622', |
||
62 | 'securityIdType' => 'CUSIP', |
||
63 | 'units' => '', |
||
64 | 'unitPrice' => '', |
||
65 | 'total' => '12.59', |
||
66 | 'incomeType' => 'DIV', |
||
67 | 'subAccountSec' => 'CASH', |
||
68 | 'subAccountFund' => 'CASH', |
||
69 | 'actionCode' => 'INCOME', |
||
70 | ), |
||
71 | '200200' => array( |
||
72 | 'tradeDate' => new \DateTime('2011-02-01'), |
||
73 | 'settlementDate' => new \DateTime('2011-02-01'), |
||
74 | 'securityId' => '355055155', |
||
75 | 'securityIdType' => 'CUSIP', |
||
76 | 'units' => '0.037', |
||
77 | 'unitPrice' => '187.9894', |
||
78 | 'total' => '-6.97', |
||
79 | 'incomeType' => 'DIV', |
||
80 | 'subAccountSec' => 'CASH', |
||
81 | 'subAccountFund' => '', |
||
82 | 'actionCode' => 'REINVEST', |
||
83 | ), |
||
84 | '300100' => array( |
||
85 | 'date' => new \DateTime('2010-01-15'), |
||
86 | 'type' => 'OTHER', |
||
87 | 'amount' => 1234.56, |
||
88 | 'actionCode' => 'INVBANKTRAN', |
||
89 | ), |
||
90 | ); |
||
91 | |||
92 | if (count($expected)) { |
||
93 | self::assertTrue(count($account->statement->transactions) > 0); |
||
94 | } |
||
95 | |||
96 | $this->validateTransactions($account->statement->transactions, $expected); |
||
97 | } |
||
241 |