Rommeo Posted May 24, 2019 Share Posted May 24, 2019 (edited) I'm getting an error like : Fatal error: Declaration of Cog\YouTrack\Rest\Authenticator\CookieAuthenticator::authenticate (Cog\Contracts\YouTrack\Rest\Client\Client $client): Cog\YouTrack\Rest\Authenticator\void must be compatible with Cog\Contracts\YouTrack\Rest\Authenticator\Authenticator::authenticate (Cog\Contracts\YouTrack\Rest\Client\Client $client): Cog\Contracts\YouTrack\Rest\Authenticator\void in /var/www/html/vendor/cybercog/youtrack-rest-php/src/Authenticator/CookieAuthenticator.php on line 24 my index file is : require_once 'vendor/autoload.php'; use Cog\YouTrack\Rest; // use Cog\Contracts\YouTrack\Rest\Authenticator\Authenticator; // Application configuration (replace with your YouTrack server values) $apiBaseUri = 'http://111.111.111.111:8080'; $apiUsername = 'username'; $apiPassword = 'password'; // Instantiate PSR-7 HTTP Client $psrHttpClient = new \GuzzleHttp\Client([ 'base_uri' => $apiBaseUri, 'debug' => true, ]); // Instantiate YouTrack API HTTP Client $httpClient = new Rest\HttpClient\GuzzleHttpClient($psrHttpClient); // Instantiate YouTrack API Cookie Authenticator $authenticator = new Rest\Authenticator\CookieAuthenticator(); CookieAuthenticator.php file is : namespace Cog\YouTrack\Rest\Authenticator; use Cog\Contracts\YouTrack\Rest\Authenticator\Authenticator as AuthenticatorContract; use Cog\Contracts\YouTrack\Rest\Client\Client as ClientContract; /** * Class CookieAuthenticator. * * @package Cog\YouTrack\Rest\Authenticator */ class CookieAuthenticator implements AuthenticatorContract // <--line 24 where the error is { /** * @var string */ private $username = ''; /** * @var string */ private $password = ''; /** * @var string */ private $cookie = ''; /** * Determine is trying to authenticate. * * @var bool */ private $isAuthenticating = false; /** * CookieAuthenticator constructor. * * @param string $username * @param string $password */ public function __construct(string $username, string $password) { $this->username = $username; $this->password = $password; } /** * Authenticate client and returns cookie on success login. * * @param \Cog\Contracts\YouTrack\Rest\Client\Client $client * @return void * * @throws \Cog\Contracts\YouTrack\Rest\Authenticator\Exceptions\AuthenticationException */ public function authenticate(ClientContract $client): void { $client = new ClientContract; if ($this->cookie !== '' || $this->isAuthenticating) { return; } $this->isAuthenticating = true; $response = $client->request('POST', '/user/login', [ 'login' => $this->username, 'password' => $this->password, ]); $this->isAuthenticating = false; if ($response->isStatusCode(200)) { $this->cookie = $response->cookie(); } } /** * Retrieve authentication token. * * @return string */ public function token(): string { return $this->cookie; } } Why I'm getting this error? I think there is something wrong with CookieAuthanticator.php file but unfortunately I could not find it Edited May 24, 2019 by Rommeo Quote Link to comment https://forums.phpfreaks.com/topic/308752-declaration-error-help-needed/ Share on other sites More sharing options...
requinix Posted May 24, 2019 Share Posted May 24, 2019 The definition of CookieAuthenticator::authenticate() does not match Authenticator::authenticate(). Look at the interface's version and compare to what yours is. Quote Link to comment https://forums.phpfreaks.com/topic/308752-declaration-error-help-needed/#findComment-1567054 Share on other sites More sharing options...
Rommeo Posted May 24, 2019 Author Share Posted May 24, 2019 But it looks like same : Here is Authenticator::authenticate() namespace Cog\Contracts\YouTrack\Rest\Authenticator; use Cog\Contracts\YouTrack\Rest\Client\Client as ClientContract; /** * Interface Authorizer. * * @package Cog\Contracts\YouTrack\Rest\Authenticator */ interface Authenticator { /** * Authenticate API Client. * * @param \Cog\Contracts\YouTrack\Rest\Client\Client $client * @return void * * @throws \Cog\Contracts\YouTrack\Rest\Authenticator\Exceptions\AuthenticationException */ public function authenticate(ClientContract $client): void; /** * Retrieve authentication token. * * @return string */ public function token(): string; } Quote Link to comment https://forums.phpfreaks.com/topic/308752-declaration-error-help-needed/#findComment-1567055 Share on other sites More sharing options...
requinix Posted May 24, 2019 Share Posted May 24, 2019 Ah, I missed it earlier: Cog\YouTrack\Rest\Authenticator\void You need to be running PHP 7.1 or later to use the "void" typehint. Quote Link to comment https://forums.phpfreaks.com/topic/308752-declaration-error-help-needed/#findComment-1567056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.