<commit_before><?php

namespace TrelloBundle\Service;

use DateTime;
use Trello\Client;

class CardMovedService
{

    /**
     *
     * @var Client
     */
    private $trelloApiClient;

    function __construct(Client $trelloApiClient)
    {
        $this->trelloApiClient = $trelloApiClient;
    }

    public function getCardsOpenByList($listId)
    {
        return $this->trelloApiClient->api('lists')->cards()->filter($listId, 'open');
    }

    public function getMovedCardsByList($listId)
    {
        $cards = $this->getCardsOpenByList($listId);
        $movedCards = [];


        foreach ($cards as $card) {

            $action = $this->trelloApiClient->api('card')->actions()->all($card['id'], [
                'filter' => 'updateCard',
            ]);

            $lastListId = isset($action[0]['data']['listAfter']['id']) ? $action[0]['data']['listAfter']['id'] : $action[0]['data']['list']['id'];

            if ($lastListId == $listId) {

                $action[0]['date'] = $this->parseTimezoneForDate($action[0]['date']);

                if ($this->isNewCard($listId, $action[0]['date'])) {

                    $movedCards[$card['id']]['card'] = $card;
                    $movedCards[$card['id']]['action'] = $action[0];
                }
            }
        }

        return $movedCards;
    }

    private function getLastSyncForList($listId)
    {
        $lastSync['56cde648b6815a552e5f9065'] = "2016-08-08 17:18:10";
        $lastSync['57a8e8aa51c27ef632a540f8'] = "2016-08-09 17:10:27";

        return isset($lastSync[$listId]) ? $lastSync[$listId] : null;
    }

    private function isNewCard($listId, $dateForAction)
    {
        if (strtotime($this->getLastSyncForList($listId)) < strtotime($dateForAction)) {
            return true;
        }

        return false;
    }

    private function parseTimezoneForDate($oldDate)
    {
        $date = new DateTime($oldDate);
        date_sub($date, date_interval_create_from_date_string('3 hours'));
        return $date->format('Y-m-d H:i:s');
    }

    public function registerNewCardMoved($card)
    {
        print_r($card);
    }

}<commit_msg>trazendo apenas cards movidos<commit_after><?php

namespace TrelloBundle\Service;

use DateTime;
use Trello\Client;

class CardMovedService
{

    /**
     *
     * @var Client
     */
    private $trelloApiClient;

    function __construct(Client $trelloApiClient)
    {
        $this->trelloApiClient = $trelloApiClient;
    }

    public function getCardsOpenByList($listId)
    {
        return $this->trelloApiClient->api('lists')->cards()->filter($listId, 'open');
    }

    public function getMovedCardsByList($listId)
    {
        $cards      = $this->getCardsOpenByList($listId);
        $movedCards = [];


        foreach ($cards as $card) {

            $action = $this->trelloApiClient->api('card')->actions()->all($card['id'], [
                'filter' => 'updateCard',
            ]);

            if (!isset($action[0]['data']['listAfter']['id'])) {
                continue;
            }

            $lastListId = $action[0]['data']['listAfter']['id'];

            if ($lastListId == $listId) {

                $action[0]['date'] = $this->parseTimezoneForDate($action[0]['date']);

                if ($this->isNewCard($listId, $action[0]['date'])) {

                    $movedCards[$card['id']]['card']   = $card;
                    $movedCards[$card['id']]['action'] = $action[0];
                }
            }
        }

        return $movedCards;
    }

    private function getLastSyncForList($listId)
    {
        $lastSync['56cde648b6815a552e5f9065'] = "2016-08-08 17:18:10";
        $lastSync['57a8e8aa51c27ef632a540f8'] = "2016-08-10 15:03:55";

        return isset($lastSync[$listId]) ? $lastSync[$listId] : null;
    }

    private function isNewCard($listId, $dateForAction)
    {
        if (strtotime($this->getLastSyncForList($listId)) < strtotime($dateForAction)) {
            return true;
        }

        return false;
    }

    private function parseTimezoneForDate($oldDate)
    {
        $date = new DateTime($oldDate);
        date_sub($date, date_interval_create_from_date_string('3 hours'));
        return $date->format('Y-m-d H:i:s');
    }

    public function registerNewCardMoved($card)
    {
        print_r($card);
    }

}
{'fraction_non_alphanumeric': 0.16508889401985685, 'fraction_numerical': 0.03117063033941353, 'mean_word_length': 2.4029850746268657, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, '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': '2358483', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1365, 'n_words': 196}