setState() public method

public setState ( integer $state )
$state integer
Example #1
0
 /**
  * Updates repo based on status from travis.
  *
  * @param  Bundle $bundle
  *
  * @return boolean
  */
 public function update(Bundle $bundle)
 {
     $this->output->write(' Travis status:');
     $response = $this->browser->get('http://travis-ci.org/' . $bundle->getOwnerName() . '/' . $bundle->getName() . '.json');
     $status = json_decode($response->getContent(), true);
     if (JSON_ERROR_NONE === json_last_error()) {
         $lastBuildAt = new \DateTime();
         $lastBuildAt->setTimestamp(strtotime($status['last_build_finished_at']));
         // Only execute if date of last build is older than last update of bundle
         if ($lastBuildAt < $bundle->getUpdatedAt()) {
             $state = Activity::STATE_UNKNOWN;
             if (0 === $status['last_build_status']) {
                 $bundle->setTravisCiBuildStatus(true);
                 $state = Activity::STATE_OPEN;
                 $this->output->write(' success');
             } elseif (1 === $status['last_build_status']) {
                 $bundle->setTravisCiBuildStatus(false);
                 $state = Activity::STATE_CLOSED;
                 $this->output->write(' failed');
             }
             if (Activity::STATE_UNKNOWN !== $state) {
                 $activity = new Activity();
                 $activity->setType(Activity::ACTIVITY_TYPE_TRAVIS_BUILD);
                 $activity->setState($state);
                 $activity->setBundle($bundle);
                 return true;
             }
         } else {
             $this->output->write(' skipped');
             return true;
         }
     }
     $bundle->setTravisCiBuildStatus(null);
     $this->output->write(' error');
     return false;
 }