Code Duplication    Length = 23-27 lines in 3 locations

app/Containers/Payment/Tasks/DeletePaymentAccountTask.php 1 location

@@ 16-38 (lines=23) @@
13
 *
14
 * @author  Johannes Schobel <[email protected]>
15
 */
16
class DeletePaymentAccountTask extends Task
17
{
18
19
    protected $repository;
20
21
    public function __construct(PaymentAccountRepository $repository)
22
    {
23
        $this->repository = $repository;
24
    }
25
26
    public function run(PaymentAccount $account)
27
    {
28
        try {
29
            // first, get the associated account and remove this one!
30
            $account->accountable->delete();
31
32
            // then remove the payment account
33
            return $this->repository->delete($account->id);
34
        } catch (Exception $exception) {
35
            throw new DeleteResourceFailedException();
36
        }
37
    }
38
}
39

app/Containers/Payment/Tasks/FindPaymentAccountByIdTask.php 1 location

@@ 17-43 (lines=27) @@
14
 * @author  Johannes Schobel <[email protected]>
15
 * @author  Mahmoud Zalt  <[email protected]>
16
 */
17
class FindPaymentAccountByIdTask extends Task
18
{
19
20
    protected $repository;
21
22
    public function __construct(PaymentAccountRepository $repository)
23
    {
24
        $this->repository = $repository;
25
    }
26
27
    /**
28
     * @param $id
29
     *
30
     * @return  mixed
31
     * @throws  NotFoundException
32
     */
33
    public function run($id): PaymentAccount
34
    {
35
        try {
36
            $paymentAccount = $this->repository->find($id);
37
        } catch (Exception $exception) {
38
            throw new NotFoundException();
39
        }
40
41
        return $paymentAccount;
42
    }
43
}
44

app/Containers/Payment/Tasks/UpdatePaymentAccountTask.php 1 location

@@ 16-40 (lines=25) @@
13
 *
14
 * @author  Johannes Schobel <[email protected]>
15
 */
16
class UpdatePaymentAccountTask extends Task
17
{
18
    protected $repository;
19
20
    public function __construct(PaymentAccountRepository $repository)
21
    {
22
        $this->repository = $repository;
23
    }
24
25
    /**
26
     * @param \App\Containers\Payment\Models\PaymentAccount $account
27
     * @param array                                         $data
28
     *
29
     * @return mixed
30
     * @throws UpdateResourceFailedException
31
     */
32
    public function run(PaymentAccount $account, array $data)
33
    {
34
        try {
35
            return $this->repository->update($data, $account->id);
36
        } catch (Exception $exception) {
37
            throw new UpdateResourceFailedException();
38
        }
39
    }
40
}
41