Complex classes like Record often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Record, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 11 | class Record  | 
            ||
| 12 | { | 
            ||
| 13 | /**  | 
            ||
| 14 | * @var Entry  | 
            ||
| 15 | */  | 
            ||
| 16 | private $entryDecoder;  | 
            ||
| 17 | /**  | 
            ||
| 18 | * @var DateDecoderInterface  | 
            ||
| 19 | */  | 
            ||
| 20 | private $dateDecoder;  | 
            ||
| 21 | |||
| 22 | /**  | 
            ||
| 23 | * Record constructor.  | 
            ||
| 24 | * @param Entry $entryDecoder  | 
            ||
| 25 | * @param DateDecoderInterface $dateDecoder  | 
            ||
| 26 | */  | 
            ||
| 27 | 31 | public function __construct(Entry $entryDecoder, DateDecoderInterface $dateDecoder)  | 
            |
| 32 | |||
| 33 | /**  | 
            ||
| 34 | * @param DTO\Record $record  | 
            ||
| 35 | * @param SimpleXMLElement $xmlRecord  | 
            ||
| 36 | */  | 
            ||
| 37 | 19 | public function addBalances(DTO\Record $record, SimpleXMLElement $xmlRecord)  | 
            |
| 38 |     { | 
            ||
| 39 | 19 | $xmlBalances = $xmlRecord->Bal;  | 
            |
| 
                                                                                                    
                        
                         | 
                |||
| 40 | 19 |         foreach ($xmlBalances as $xmlBalance) { | 
            |
| 41 | 14 | $amount = StringToUnits::convert((string) $xmlBalance->Amt);  | 
            |
| 42 | 14 | $currency = (string)$xmlBalance->Amt['Ccy'];  | 
            |
| 43 | 14 | $date = (string)$xmlBalance->Dt->Dt;  | 
            |
| 44 | |||
| 45 | 14 |             if ((string) $xmlBalance->CdtDbtInd === 'DBIT') { | 
            |
| 46 | 9 | $amount = $amount * -1;  | 
            |
| 47 | }  | 
            ||
| 48 | |||
| 49 | 14 |             if (isset($xmlBalance->Tp) && isset($xmlBalance->Tp->CdOrPrtry)) { | 
            |
| 50 | 14 | $code = (string) $xmlBalance->Tp->CdOrPrtry->Cd;  | 
            |
| 51 | |||
| 52 | 14 |                 if (in_array($code, ['OPBD', 'PRCD'])) { | 
            |
| 53 | 11 | $record->addBalance(DTO\Balance::opening(  | 
            |
| 54 | 11 | new Money(  | 
            |
| 55 | 11 | $amount,  | 
            |
| 56 | 11 | new Currency($currency)  | 
            |
| 57 | ),  | 
            ||
| 58 | 11 | $this->dateDecoder->decode($date)  | 
            |
| 59 | ));  | 
            ||
| 60 | 13 |                 } elseif ($code === 'CLBD') { | 
            |
| 61 | 10 | $record->addBalance(DTO\Balance::closing(  | 
            |
| 62 | 10 | new Money(  | 
            |
| 63 | 10 | $amount,  | 
            |
| 64 | 10 | new Currency($currency)  | 
            |
| 65 | ),  | 
            ||
| 66 | 14 | $this->dateDecoder->decode($date)  | 
            |
| 67 | ));  | 
            ||
| 68 | }  | 
            ||
| 69 | }  | 
            ||
| 70 | }  | 
            ||
| 71 | 19 | }  | 
            |
| 72 | |||
| 73 | /**  | 
            ||
| 74 | * @param DTO\Record $record  | 
            ||
| 75 | * @param SimpleXMLElement $xmlRecord  | 
            ||
| 76 | */  | 
            ||
| 77 | 22 | public function addEntries(DTO\Record $record, SimpleXMLElement $xmlRecord)  | 
            |
| 196 | }  | 
            ||
| 197 | 
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.