Completed
Pull Request — master (#71)
by Olatunbosun
16:04
created

PaystackManager::getFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Laravel Paystack package.
7
 *
8
 * (c) Prosper Otemuyiwa <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Unicodeveloper\Paystack;
15
16
/**
17
 * @method \Xeviant\Paystack\Api\Customers customers()
18
 * @method \Xeviant\Paystack\Api\Balance balance()
19
 * @method \Xeviant\Paystack\Api\Bank bank()
20
 * @method \Xeviant\Paystack\Api\BulkCharges bulkCharges()
21
 * @method \Xeviant\Paystack\Api\Bvn bvn()
22
 * @method \Xeviant\Paystack\Api\Charge charge()
23
 * @method \Xeviant\Paystack\Api\Integration integration()
24
 * @method \Xeviant\Paystack\Api\Invoices invoices()
25
 * @method \Xeviant\Paystack\Api\Pages pages()
26
 * @method \Xeviant\Paystack\Api\Plans plans()
27
 * @method \Xeviant\Paystack\Api\Refund refund()
28
 * @method \Xeviant\Paystack\Api\Settlements settlements()
29
 * @method \Xeviant\Paystack\Api\SubAccount subAccount()
30
 * @method \Xeviant\Paystack\Api\Subscriptions subscriptions()
31
 * @method \Xeviant\Paystack\Api\Transactions transactions()
32
 * @method \Xeviant\Paystack\Api\TransferRecipients transferRecipients()
33
 * @method \Xeviant\Paystack\Api\Transfers transfers()
34
 */
35
36
37
use GrahamCampbell\Manager\AbstractManager;
38
use Illuminate\Config\Repository;
39
40
class PaystackManager extends AbstractManager
41
{
42
    /**
43
     * @var PaystackFactory
44
     */
45
    private $factory;
46
47
    /**
48
     * PaystackManager constructor.
49
     *
50
     * @param Repository $repository
51
     * @param PaystackFactory $factory
52
     */
53
    public function __construct(Repository $repository, PaystackFactory $factory)
54
    {
55
        parent::__construct($repository);
56
        $this->factory = $factory;
57
    }
58
59
    /**
60
     * Create the connection instance.
61
     *
62
     * @param array $config
63
     *
64
     * @return \Xeviant\Paystack\Client
65
     */
66
    protected function createConnection(array $config)
67
    {
68
        return $this->factory->make($config);
69
    }
70
71
    /**
72
     * Get the configuration name.
73
     *
74
     * @return string
75
     */
76
    protected function getConfigName()
77
    {
78
        return 'paystack';
79
    }
80
81
    /**
82
     * Gets the instance of the Paystack Factory
83
     *
84
     * @return PaystackFactory
85
     */
86
    public function getFactory()
87
    {
88
        return $this->factory;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function __call(string $method, array $parameters)
95
    {
96
        $legacyObject = $this->getLegacyObject();
97
98
        if (method_exists($legacyObject, $method)) {
99
            return $legacyObject->{$method}(...$parameters);
100
        }
101
102
        return parent::__call($method, $parameters);
103
    }
104
105
    /**
106
     * Gets the Legacy Paystack Object from v1 of this package
107
     *
108
     * @return Paystack
109
     */
110
    protected function getLegacyObject()
111
    {
112
        return new Paystack;
113
    }
114
}
115