Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
Twitter
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 getRequestTokenUrl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAuthorizeUrl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAccessTokenUrl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUserProfile
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 getLogoSource
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getThemeColor
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Miniframe\SocialLogin\Provider;
4
5use Miniframe\SocialLogin\Model\User;
6
7class Twitter extends AbstractOAuth1Provider
8{
9    /**
10     * Returns the request token URL
11     *
12     * @return string
13     */
14    protected function getRequestTokenUrl(): string
15    {
16        return 'https://api.twitter.com/oauth/request_token';
17    }
18
19    /**
20     * Returns the authorize URL
21     *
22     * @return string
23     */
24    protected function getAuthorizeUrl(): string
25    {
26        return 'https://api.twitter.com/oauth/authorize';
27    }
28
29    /**
30     * Returns the access token URL
31     *
32     * @return string
33     */
34    protected function getAccessTokenUrl(): string
35    {
36        return 'https://api.twitter.com/oauth/access_token';
37    }
38
39    /**
40     * Returns the user profile
41     *
42     * @param array $accessToken The access token.
43     *
44     * @return User
45     */
46    protected function getUserProfile(array $accessToken): User
47    {
48        // Compiles the request
49        $data = [
50            'screen_name' => $accessToken['screen_name'],
51            'oauth_token' => $accessToken['oauth_token'],
52        ];
53        $requestMethod = 'GET';
54        $url = 'https://api.twitter.com/1.1/users/show.json';
55        $headers = [$this->generateOAuthHeader($url, 'GET', $data, $accessToken['oauth_token_secret'])];
56
57        // Fetch user data
58        $data = $this->curlRequest($url, $requestMethod, $data, $headers);
59
60        return new User(
61            $accessToken['user_id'],
62            $accessToken['screen_name'],
63            $data['name'],
64            $data['profile_image_url_https'],
65            __CLASS__,
66            ['accessToken' => $accessToken, 'userData' => $data]
67        );
68    }
69
70    /**
71     * Returns the image source for the logo of this provider.
72     *
73     * @return string
74     */
75    public static function getLogoSource(): string
76    {
77        return 'data:image/svg+xml;base64,'
78            . base64_encode(file_get_contents(__DIR__ . '/../../templates/logos/Twitter.svg'));
79    }
80
81    /**
82     * Returns the theme color for this provider.
83     *
84     * @return string
85     */
86    public static function getThemeColor(): string
87    {
88        return 'rgba(30,41,51,255)';
89    }
90}