Test Setup Failed
Push — master ( ba8aba...70cbb0 )
by Philippe
10:29
created

AccountController::injectPersistenceManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/*
3
 * This program is free software: you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation, either version 3 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 */
16
namespace Filoucrackeur\Hubic\Controller\Backend;
17
18
use Filoucrackeur\Hubic\Domain\Model\Account;
19
use Filoucrackeur\Hubic\Domain\Repository\AccountRepository;
20
use Filoucrackeur\Hubic\Service\OAuth2\Client;
21
use TYPO3\CMS\Core\Messaging\AbstractMessage;
22
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
23
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
24
25
/**
26
 * Class AccountController
27
 * @package Filoucrackeur\Hubic\Controller\Backend
28
 */
29
class AccountController extends ActionController
30
{
31
    /**
32
     * @var \Filoucrackeur\Hubic\Domain\Repository\AccountRepository
33
     */
34
    protected $accountRepository;
35
36
    /**
37
     * @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
38
     */
39
    protected $persistenceManager;
40
41
    /**
42
     * @var \Filoucrackeur\Hubic\Utility\ClientUtility
43
     */
44
    protected $client;
45
46
    /**
47
     * @param AccountRepository $accountRepository
48
     */
49
    public function injectAccountRepository(AccountRepository $accountRepository) : void
50
    {
51
        $this->accountRepository = $accountRepository;
52
    }
53
54
    /**
55
     * @param PersistenceManager $persistenceManager
56
     */
57
    public function injectPersistenceManager(PersistenceManager $persistenceManager) : void
58
    {
59
        $this->persistenceManager = $persistenceManager;
60
    }
61
62
    /**
63
     * @param Client $client
64
     */
65
    public function injectClient(Client $client) : void
66
    {
67
        $this->client = $client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $client of type object<Filoucrackeur\Hubic\Service\OAuth2\Client> is incompatible with the declared type object<Filoucrackeur\Hubic\Utility\ClientUtility> of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
68
    }
69
70
    public function indexAction() : void
71
    {
72
        $accounts = $this->accountRepository->findAll();
73
        $this->view->assign('accounts', $accounts);
74
    }
75
76
    /**
77
     * @param Account $account
78
     */
79
    public function showAction(Account $account) : void
80
    {
81
        if ($account->getAccessToken()) {
82
            $this->client->callHubic($account);
83
            $clientAccount = $this->client->getAccount();
84
            $clientAccountQuota = $this->client->getAccountQuota();
85
            $agreement = $this->client->getAgreement();
86
            $links = $this->client->getAllLinks();
87
            $this->view->assignMultiple([
88
                'account' => $account,
89
                'clientAccount' => $clientAccount,
90
                'clientAccountQuota' => $clientAccountQuota,
91
                'agreement' => $agreement,
92
                'links' => $links
93
            ]);
94
        } else {
95
            $this->view->assign('account', $account);
96
        }
97
    }
98
99
    /**
100
     * @param Account $account
101
     */
102
    public function authenticationRequestAction(Account $account) : void
103
    {
104
105
        $account->setAccessToken('');
106
        $this->persistenceManager->update($account);
107
        $this->persistenceManager->persistAll();
108
109
        $this->client->setAccount($account);
110
        $this->redirectToUri($this->client->getAuthorizationRequestUrl($account));
111
    }
112
113
    /**
114
     * @param Account $account
115
     */
116
    public function authenticationResponseAction(Account $account) : void
117
    {
118
        if( $this->client->callHubic($account) ){
119
            $this->addFlashMessage('Token successfully added', 'Authentication request', AbstractMessage::OK);
120
        }else {
121
            $this->addFlashMessage('Failed getting token please check client ID and client secret', 'Authentication request', AbstractMessage::ERROR);
122
        }
123
        $this->redirect('show', '', '', ['account' => $account]);
124
    }
125
126
    public function addAction() {
127
128
    }
129
130
131
    /**
132
     * @param Account $account
133
     */
134
    public function deleteAction(Account $account) : void
135
    {
136
        $this->persistenceManager->remove($account);
137
        $this->addFlashMessage('Account successfully deleted', 'Account', AbstractMessage::OK);
138
        $this->redirect('index');
139
    }
140
141
    /**
142
     * @param Account $account
143
     */
144
    public function unlinkAction(Account $account) : void
145
    {
146
        $account->setAccessToken('');
147
        $this->persistenceManager->update($account);
148
        $this->persistenceManager->persistAll();
149
        $this->addFlashMessage('Account successfully unlinked', 'Account', AbstractMessage::OK);
150
        $this->redirect('show', '', '', ['account' => $account]);
151
    }
152
}
153