| Total Complexity | 41 |
| Total Lines | 264 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like IPI 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.
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 IPI, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class IPI |
||
| 10 | { |
||
| 11 | public $descCST; |
||
| 12 | public $clEnq; |
||
| 13 | public $CodNCM; |
||
| 14 | public $REIDE; |
||
| 15 | public $SUFRAMA; |
||
| 16 | public $CSTNotaRef; |
||
| 17 | |||
| 18 | private $CNPJProd; |
||
| 19 | private $cSelo; |
||
| 20 | private $qSelo; |
||
| 21 | private $cEnq; |
||
| 22 | private $CST; |
||
| 23 | private $vBC; |
||
| 24 | private $pIPI; |
||
| 25 | private $vIPI; |
||
| 26 | private $qUnid; |
||
| 27 | private $vUnid; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param $IPI |
||
| 31 | * @return mixed |
||
| 32 | * @throws Exception |
||
| 33 | */ |
||
| 34 | public static function calcular(IPI $IPI): void |
||
| 35 | { |
||
| 36 | if ($IPI->getCST() === '00') { |
||
| 37 | /* ENTRADA COM RECUPERAÇÃO DE CRÉDITO */ |
||
| 38 | return self::calcAliquotaAdValoren($IPI); |
||
| 39 | } elseif ($IPI->getCST() === '49') { |
||
| 40 | /* OUTRAS ENTRADAS */ |
||
| 41 | return self::calcRetornoIsentoValorOutros($IPI); |
||
| 42 | } elseif ($IPI->getCST() === '50') { |
||
| 43 | /* SAÍDA TRIBUTADA */ |
||
| 44 | return self::calcAliquotaAdValoren($IPI); |
||
| 45 | } elseif ($IPI->getCST() === '99') { |
||
| 46 | /* OUTRAS SAÍDAS */ |
||
| 47 | return self::calcAliquotaAdValoren($IPI); |
||
| 48 | } elseif ($IPI->getCST() === '01') { |
||
| 49 | /* 01 ENTRADA TRIBUTADA COM ALICOTA ZERO */ |
||
| 50 | return self::calcIsento($IPI); |
||
| 51 | } elseif ($IPI->getCST() === '02') { |
||
| 52 | /* ENTRADA ISENTA */ |
||
| 53 | return self::calcIsento($IPI); |
||
| 54 | } elseif ($IPI->getCST() === '03') { |
||
| 55 | /* ENTRADA NÃO TRIBUTADA */ |
||
| 56 | return self::calcIsento($IPI); |
||
| 57 | } elseif ($IPI->getCST() === '04') { |
||
| 58 | /* ENTRADA IMUNE */ |
||
| 59 | return self::calcIsento($IPI); |
||
| 60 | } elseif ($IPI->getCST() === '05') { |
||
| 61 | /* ENTRADA COM SUSPENSAO */ |
||
| 62 | return self::calcIsento($IPI); |
||
| 63 | } elseif ($IPI->getCST() === '51') { |
||
| 64 | /* SAÍDA TRIBUTADA COM ALICOTA ZERO */ |
||
| 65 | return self::calcIsento($IPI); |
||
| 66 | } elseif ($IPI->getCST() === '52') { |
||
| 67 | /* SAÍDA ISENTA */ |
||
| 68 | return self::calcIsento($IPI); |
||
| 69 | } elseif ($IPI->getCST() === '53') { |
||
| 70 | /* SAÍDA NÃO-TRIBUTADA */ |
||
| 71 | return self::calcIsento($IPI); |
||
| 72 | } elseif ($IPI->getCST() === '54') { |
||
| 73 | /* SAÍDA IMUNE */ |
||
| 74 | return self::calcIsento($IPI); |
||
| 75 | } elseif ($IPI->getCST() === '55') { |
||
| 76 | /* SAÍDA COM SUSPENSAO */ |
||
| 77 | return self::calcIsento($IPI); |
||
| 78 | } |
||
| 79 | throw new Exception('Erro ao calcular IPI' . print_r($IPI, true)); |
||
| 80 | } |
||
| 81 | |||
| 82 | /* |
||
| 83 | * @ISENTO |
||
| 84 | */ |
||
| 85 | private static function calcIsento($IPI) |
||
| 86 | { |
||
| 87 | $IPI->vIPI = '0'; |
||
| 88 | $IPI->vBC = '0'; |
||
| 89 | $IPI->pIPI = '0'; |
||
| 90 | $IPI->qUnid = null; |
||
| 91 | $IPI->vUnid = null; |
||
| 92 | return $IPI; |
||
| 93 | } |
||
| 94 | |||
| 95 | /* |
||
| 96 | * @Calcula o Valor IPI Ad Valoren |
||
| 97 | */ |
||
| 98 | private static function calcAliquotaAdValoren($IPI) |
||
| 99 | { |
||
| 100 | $IPI->vIPI = ($IPI->vBC * ($IPI->pIPI / 100)); |
||
| 101 | return $IPI; |
||
| 102 | } |
||
| 103 | |||
| 104 | private static function calcRetornoIsentoValorOutros($IPI) |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @return string |
||
| 117 | */ |
||
| 118 | public function getCNPJProd(): string |
||
| 119 | { |
||
| 120 | return $this->CNPJProd; |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @param string $CNPJProd |
||
| 125 | */ |
||
| 126 | public function setCNPJProd(string $CNPJProd): void |
||
| 127 | { |
||
| 128 | $this->CNPJProd = $CNPJProd; |
||
| 129 | } |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @return string |
||
| 133 | */ |
||
| 134 | public function getCSelo(): string |
||
| 135 | { |
||
| 136 | return $this->cSelo; |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @param string $cSelo |
||
| 141 | */ |
||
| 142 | public function setCSelo(string $cSelo): void |
||
| 143 | { |
||
| 144 | $this->cSelo = $cSelo; |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @return float |
||
| 149 | */ |
||
| 150 | public function getQSelo(): float |
||
| 151 | { |
||
| 152 | return $this->qSelo; |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param float $qSelo |
||
| 157 | */ |
||
| 158 | public function setQSelo(float $qSelo): void |
||
| 159 | { |
||
| 160 | $this->qSelo = $qSelo; |
||
| 161 | } |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @return string |
||
| 165 | */ |
||
| 166 | public function getCEnq(): string |
||
| 167 | { |
||
| 168 | return $this->cEnq; |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @param string $cEnq |
||
| 173 | */ |
||
| 174 | public function setCEnq(string $cEnq): void |
||
| 175 | { |
||
| 176 | $this->cEnq = $cEnq; |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | public function getCST(): string |
||
| 183 | { |
||
| 184 | return $this->CST; |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param string $CST |
||
| 189 | */ |
||
| 190 | public function setCST(string $CST): void |
||
| 191 | { |
||
| 192 | $this->CST = $CST; |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @return float |
||
| 197 | */ |
||
| 198 | public function getVBC(): float |
||
| 199 | { |
||
| 200 | return $this->vBC; |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @param float $vBC |
||
| 205 | */ |
||
| 206 | public function setVBC(float $vBC): void |
||
| 207 | { |
||
| 208 | $this->vBC = $vBC; |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @return float |
||
| 213 | */ |
||
| 214 | public function getPIPI(): float |
||
| 215 | { |
||
| 216 | return $this->pIPI; |
||
| 217 | } |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @param float $pIPI |
||
| 221 | */ |
||
| 222 | public function setPIPI(float $pIPI): void |
||
| 223 | { |
||
| 224 | $this->pIPI = $pIPI; |
||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return float |
||
| 229 | */ |
||
| 230 | public function getVIPI(): float |
||
| 231 | { |
||
| 232 | return $this->vIPI; |
||
| 233 | } |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @param float $vIPI |
||
| 237 | */ |
||
| 238 | public function setVIPI(float $vIPI): void |
||
| 239 | { |
||
| 240 | $this->vIPI = $vIPI; |
||
| 241 | } |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @return float |
||
| 245 | */ |
||
| 246 | public function getQUnid(): float |
||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @param float $qUnid |
||
| 253 | */ |
||
| 254 | public function setQUnid(float $qUnid): void |
||
| 255 | { |
||
| 256 | $this->qUnid = $qUnid; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @return float |
||
| 261 | */ |
||
| 262 | public function getVUnid(): float |
||
| 263 | { |
||
| 264 | return $this->vUnid; |
||
| 265 | } |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @param float $vUnid |
||
| 269 | */ |
||
| 270 | public function setVUnid(float $vUnid): void |
||
| 273 | } |
||
| 274 | } |
||
| 275 |