<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\Annotation as BaseAnnotation;
use function React\Promise\reject;
use function React\Promise\resolve;

class Annotation extends BaseAnnotation
{
    /**
     * @return PromiseInterface
     */
    public function refresh() : PromiseInterface
    {
        return $this->handleCommand(
            new SimpleRequestCommand('jobs/' . $this->jobId() . '/annotations')
        )->then(function ($json) {
            foreach ($json['annotations'] as $annotation) {
                if ($annotation['id'] != $this->id()) {
                    continue;
                }

                return resolve($this->handleCommand(new HydrateCommand('Annotation', $annotation)));
            }

            return reject();
        });
    }
}<commit_msg>Refresh annotation using annotations command<commit_after><?php
declare(strict_types=1);

namespace ApiClients\Client\Travis\Resource\Async;

use ApiClients\Client\Travis\CommandBus\Command\AnnotationsCommand;
use ApiClients\Client\Travis\Resource\Annotation as BaseAnnotation;
use ApiClients\Client\Travis\Resource\AnnotationInterface;
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 Annotation extends BaseAnnotation
{
    /**
     * @return PromiseInterface
     */
    public function refresh() : PromiseInterface
    {
        return Promise::fromObservable(unwrapObservableFromPromise($this->handleCommand(
            new AnnotationsCommand($this->jobId())
        ))->filter(function (AnnotationInterface $annotation) {
            return $this->id() === $annotation->id();
        }));
    }
}
{'fraction_non_alphanumeric': 0.1143141153081511, 'fraction_numerical': 0.0009940357852882703, 'mean_word_length': 3.513452914798206, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '1765021', 'n_tokens_mistral': 529, 'n_tokens_neox': 534, 'n_words': 101}