Completed
Push — master ( a5ba68...917ab9 )
by Dominik
20:27 queued 18:43
created

getAzineHybridAuthService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Azine\HybridAuthBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\ParameterBag;
7
use Symfony\Component\HttpFoundation\RedirectResponse;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Hybridauth\HttpClient\Util;
11
12
class HybridEndPointController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
13
{
14
    /**
15
     * @var ParameterBag
16
     */
17
    private $requestQuery;
18
19
    /**
20
     * Process the current request.
21
     *
22
     * $request - The current request parameters. Leave as NULL to default to use $_REQUEST.
23
     *
24
     * @param Request $request
25
     *
26
     * @return RedirectResponse|Response
27
     */
28
    public function processAction(Request $request)
29
    {
30
        $provider = 'linkedin';
31
        $cookieName = $this->getAzineHybridAuthService()->getCookieName($provider);
32
33
34
        $adapter = $this->getAzineHybridAuthService()->getInstance($request->cookies->get($cookieName), $provider);
35
36
        try {
37
            $adapter->authenticate();
38
            $result = $this->getAzineHybridAuthService()->storeHybridAuthSessionData($request, $provider, json_encode($adapter->getAccessToken()));
39
        } catch (\Exception $e) {
40
            throw new \Exception("Unable to create adapter for provider '$provider'. Is it configured properly?", $e->getCode(), $e);
41
        }
42
43
        $response = new RedirectResponse($this->generateUrl('user_edit'));
44
45
        if($result instanceof Cookie){
0 ignored issues
show
Bug introduced by
The class Azine\HybridAuthBundle\Controller\Cookie does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
46
47
            $response->headers->setCookie($result);
48
        }
49
50
        return $response;
51
    }
52
53
    /**
54
     * @return AzineHybridAuth
55
     */
56
    private function getAzineHybridAuthService()
57
    {
58
        return $this->get('azine_hybrid_auth_service');
59
    }
60
}
61