<commit_before><?php
declare(strict_types=1);

namespace ApiClients\Client\Travis\Resource\Async;

use ApiClients\Foundation\Hydrator\CommandBus\Command\HydrateCommand;
use ApiClients\Foundation\Transport\CommandBus\Command\SimpleRequestCommand;
use React\Promise\PromiseInterface;
use ApiClients\Client\Travis\Resource\Account as BaseAccount;
use function React\Promise\reject;
use function React\Promise\resolve;

class Account extends BaseAccount
{
    /**
     * @return PromiseInterface
     */
    public function refresh() : PromiseInterface
    {
        return $this->handleCommand(new SimpleRequestCommand('accounts'))->then(function ($json) {
            foreach ($json['accounts'] as $account) {
                if ($account['id'] != $this->id()) {
                    continue;
                }

                return resolve($this->handleCommand(new HydrateCommand('Account', $account)));
            }

            return reject();
        });
    }
}<commit_msg>Reworked account refresh<commit_after><?php
declare(strict_types=1);

namespace ApiClients\Client\Travis\Resource\Async;

use ApiClients\Client\Travis\CommandBus\Command\AccountsCommand;
use ApiClients\Client\Travis\Resource\Account as BaseAccount;
use ApiClients\Client\Travis\Resource\AccountInterface;
use React\Promise\PromiseInterface;
use Rx\React\Promise;
use function ApiClients\Tools\Rx\unwrapObservableFromPromise;
use function React\Promise\reject;
use function React\Promise\resolve;

class Account extends BaseAccount
{
    /**
     * @return PromiseInterface
     */
    public function refresh() : PromiseInterface
    {
        return Promise::fromObservable(unwrapObservableFromPromise($this->handleCommand(
            new AccountsCommand()
        ))->filter(function (AccountInterface $account) {
            return $this->id() === $account->id();
        }));
    }
}
{'fraction_non_alphanumeric': 0.1145610278372591, 'fraction_numerical': 0.0010706638115631692, 'mean_word_length': 3.5364077669902914, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3372925', 'n_tokens_mistral': 506, 'n_tokens_neox': 514, 'n_words': 95}