Jump to content

Declaration Error, help needed


Rommeo

Recommended Posts

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 :(

 

Link to comment
Share on other sites

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;
}
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.