<commit_before><?php

namespace Bolt\Extension\Bolt\Members\AccessControl;

use Carbon\Carbon;
use League\OAuth2\Client\Token\AccessToken;
use Ramsey\Uuid\Uuid;

/**
 * Authorisation state object class.
 *
 * @author <NAME> <<EMAIL>>
 */
class Authorisation implements \JsonSerializable
{
    /** @var string */
    protected $guid;
    /** @var string */
    protected $cookie;
    /** @var \DateTime */
    protected $expiry;
    /** @var AccessToken[] */
    protected $accessTokens;

    /**
     * @return string
     */
    public function getGuid()
    {
        return $this->guid;
    }

    /**
     * @param string $guid
     *
     * @return Authorisation
     */
    public function setGuid($guid)
    {
        $this->guid = $guid;

        return $this;
    }

    /**
     * @return string
     */
    public function getCookie()
    {
        if ($this->cookie === null) {
            $this->cookie = Uuid::uuid4()->toString();
        }

        return $this->cookie;
    }

    /**
     * @param string $cookie
     *
     * @return Authorisation
     */
    public function setCookie($cookie)
    {
        $this->cookie = $cookie;

        return $this;
    }

    /**
     * @return \DateTime
     */
    public function getExpiry()
    {
        return $this->expiry;
    }

    /**
     * @param \DateTime|string $expiry
     *
     * @return Authorisation
     */
    public function setExpiry($expiry)
    {
        if (is_string($expiry)) {
            $expiry = new Carbon($expiry);
        }
        $this->expiry = $expiry;

        return $this;
    }

    /**
     * @param $provider
     *
     * @param AccessToken $accessToken
     *
     * @return Authorisation
     */
    public function addAccessToken($provider, AccessToken $accessToken)
    {
        $provider = strtolower($provider);
        $this->accessTokens[$provider] = $accessToken;

        return $this;
    }

    /**
     * @param $provider
     *
     * @return AccessToken
     */
    public function getAccessToken($provider)
    {
        $provider = strtolower($provider);

        return $this->accessTokens[$provider];
    }

    /**
     * @return AccessToken
     */
    public function getAccessTokens()
    {
        return $this->accessTokens;
    }

    /**
     * @param AccessToken[] $accessTokens
     *
     * @return Authorisation
     */
    public function setAccessTokens(array $accessTokens)
    {
        $this->accessTokens = $accessTokens;

        return $this;
    }

    /**
     * @inheritDoc
     */
    public function jsonSerialize()
    {
        return [
            'guid'         => $this->guid,
            'cookie'       => $this->cookie,
            'expiry'       => $this->expiry,
            'accessTokens' => $this->accessTokens,
        ];
    }

    /**
     * Create an instance from JSON data.
     *
     * @param array|string $data
     *
     * @return Authorisation|null
     */
    public static function createFromJson($data)
    {
        if (is_string($data)) {
            $data = json_decode($data);
        }
        if (!is_array($data)) {
            return null;
        }

        $auth = new self();
        $auth->guid = $data->guid;
        $auth->cookie = $data->cookie;
        $auth->expiry = new Carbon($data->expiry->date, $data->expiry->timezone);

        foreach ((array) $data->accessTokens as $provider => $tokenData) {
            $auth->accessTokens[$provider] = new AccessToken((array) $tokenData);
        }

        return $auth;
    }
}<commit_msg>Check for stdClass not array<commit_after><?php

namespace Bolt\Extension\Bolt\Members\AccessControl;

use Carbon\Carbon;
use League\OAuth2\Client\Token\AccessToken;
use Ramsey\Uuid\Uuid;

/**
 * Authorisation state object class.
 *
 * @author <NAME> <<EMAIL>>
 */
class Authorisation implements \JsonSerializable
{
    /** @var string */
    protected $guid;
    /** @var string */
    protected $cookie;
    /** @var \DateTime */
    protected $expiry;
    /** @var AccessToken[] */
    protected $accessTokens;

    /**
     * @return string
     */
    public function getGuid()
    {
        return $this->guid;
    }

    /**
     * @param string $guid
     *
     * @return Authorisation
     */
    public function setGuid($guid)
    {
        $this->guid = $guid;

        return $this;
    }

    /**
     * @return string
     */
    public function getCookie()
    {
        if ($this->cookie === null) {
            $this->cookie = Uuid::uuid4()->toString();
        }

        return $this->cookie;
    }

    /**
     * @param string $cookie
     *
     * @return Authorisation
     */
    public function setCookie($cookie)
    {
        $this->cookie = $cookie;

        return $this;
    }

    /**
     * @return \DateTime
     */
    public function getExpiry()
    {
        return $this->expiry;
    }

    /**
     * @param \DateTime|string $expiry
     *
     * @return Authorisation
     */
    public function setExpiry($expiry)
    {
        if (is_string($expiry)) {
            $expiry = new Carbon($expiry);
        }
        $this->expiry = $expiry;

        return $this;
    }

    /**
     * @param $provider
     *
     * @param AccessToken $accessToken
     *
     * @return Authorisation
     */
    public function addAccessToken($provider, AccessToken $accessToken)
    {
        $provider = strtolower($provider);
        $this->accessTokens[$provider] = $accessToken;

        return $this;
    }

    /**
     * @param $provider
     *
     * @return AccessToken
     */
    public function getAccessToken($provider)
    {
        $provider = strtolower($provider);

        return $this->accessTokens[$provider];
    }

    /**
     * @return AccessToken
     */
    public function getAccessTokens()
    {
        return $this->accessTokens;
    }

    /**
     * @param AccessToken[] $accessTokens
     *
     * @return Authorisation
     */
    public function setAccessTokens(array $accessTokens)
    {
        $this->accessTokens = $accessTokens;

        return $this;
    }

    /**
     * @inheritDoc
     */
    public function jsonSerialize()
    {
        return [
            'guid'         => $this->guid,
            'cookie'       => $this->cookie,
            'expiry'       => $this->expiry,
            'accessTokens' => $this->accessTokens,
        ];
    }

    /**
     * Create an instance from JSON data.
     *
     * @param array|string $data
     *
     * @return Authorisation|null
     */
    public static function createFromJson($data)
    {
        if (is_string($data)) {
            $data = json_decode($data);
        }
        if (!$data instanceof \stdClass) {
            return null;
        }

        $auth = new self();
        $auth->guid = $data->guid;
        $auth->cookie = $data->cookie;
        $auth->expiry = new Carbon($data->expiry->date, $data->expiry->timezone);

        foreach ((array) $data->accessTokens as $provider => $tokenData) {
            $auth->accessTokens[$provider] = new AccessToken((array) $tokenData);
        }

        return $auth;
    }
}
{'fraction_non_alphanumeric': 0.1394922425952045, 'fraction_numerical': 0.0005641748942172073, 'mean_word_length': 1.765600624024961, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5983389', 'n_tokens_mistral': 2150, 'n_tokens_neox': 2101, 'n_words': 428}