Code Duplication    Length = 36-36 lines in 2 locations

src/Omdb.php 2 locations

@@ 61-96 (lines=36) @@
58
     * @return Title
59
     * @throws \mrcnpdlk\Xmdb\Exception
60
     */
61
    public function getByImdbId(string $imdbId)
62
    {
63
        try {
64
            $oResp = $this->oClient->getAdapter()->useCache(
65
                function () use ($imdbId) {
66
                    $oCurl = new Curl();
67
                    $oCurl->setUserAgent(UserAgent::random());
68
                    $oCurl->setHeader('Accept-Language', $this->oClient->getLang());
69
                    $params = [
70
                        'i'    => $imdbId,
71
                        'plot' => 'full',
72
                        'r'    => 'json',
73
                    ];
74
                    $oCurl->get($this->url . '&' . http_build_query($params));
75
76
                    if ($oCurl->error) {
77
                        throw new \RuntimeException('Curl Error! ' . ($oCurl->httpStatusCode ? Http::message($oCurl->httpStatusCode) : 'Unknown code'),
78
                            $oCurl->error_code);
79
                    }
80
                    if ($oCurl->response->Response !== 'True') {
81
                        throw new \RuntimeException($oCurl->response->Error);
82
                    }
83
84
                    return $oCurl->response;
85
                },
86
                [__METHOD__, $imdbId, $this->oClient->getLang()],
87
                3600 * 2)
88
            ;
89
90
91
            return Title::create($oResp);
92
93
        } catch (\Exception $e) {
94
            throw new Exception($e->getMessage(), 1, $e);
95
        }
96
    }
97
98
    /**
99
     * @param string $title
@@ 104-139 (lines=36) @@
101
     * @return Title
102
     * @throws \mrcnpdlk\Xmdb\Exception
103
     */
104
    public function getByTitle(string $title)
105
    {
106
        try {
107
            $oResp = $this->oClient->getAdapter()->useCache(
108
                function () use ($title) {
109
                    $oCurl = new Curl();
110
                    $oCurl->setUserAgent(UserAgent::random());
111
                    $oCurl->setHeader('Accept-Language', $this->oClient->getLang());
112
                    $params = [
113
                        't'    => $title,
114
                        'plot' => 'full',
115
                        'r'    => 'json',
116
                    ];
117
                    $oCurl->get($this->url . '&' . http_build_query($params));
118
119
                    if ($oCurl->error) {
120
                        throw new \RuntimeException('Curl Error! ' . ($oCurl->httpStatusCode ? Http::message($oCurl->httpStatusCode) : 'Unknown code'),
121
                            $oCurl->error_code);
122
                    }
123
                    if ($oCurl->response->Response !== 'True') {
124
                        throw new \RuntimeException($oCurl->response->Error);
125
                    }
126
127
                    return $oCurl->response;
128
                },
129
                [__METHOD__, $title, $this->oClient->getLang()],
130
                3600 * 2)
131
            ;
132
133
134
            return Title::create($oResp);
135
136
        } catch (\Exception $e) {
137
            throw new Exception($e->getMessage(), 1, $e);
138
        }
139
    }
140
}
141