Knp\Bundle\KnpBundlesBundle\Github\Developer::update PHP Method

update() public method

public update ( Developer $developer ) : boolean
$developer Knp\Bundle\KnpBundlesBundle\Entity\Developer
return boolean
    public function update(EntityDeveloper $developer)
    {
        $keywords = array($developer->getName());
        if (null !== $developer->getFullName()) {
            $keywords[] = $developer->getFullName();
        }
        if (null !== $developer->getEmail()) {
            $keywords[] = $developer->getEmail();
        }
        /** @var User $api */
        $api = $this->github->api('user');
        try {
            $data = $api->show($developer->getName());
        } catch (ApiLimitExceedException $e) {
            return false;
        } catch (RuntimeException $e) {
            // Not found via actual name? Search by other known data
            foreach ($keywords as $field) {
                // Did we found user in this iteration ?
                if (!empty($data)) {
                    break;
                }
                try {
                    $data = $api->find($field);
                    if (isset($data['users']) && 0 < count($data['users'])) {
                        $data = $data['users'][0];
                        // Let's call API one more time to get clean user data
                        $data = $api->show($data['login']);
                    }
                } catch (ApiLimitExceedException $e) {
                    // Api limit ? Then not do anything more
                    return false;
                } catch (RuntimeException $e) {
                    // Not found yet ? Continue loop
                }
            }
        }
        // Developer has been removed / not found ?
        if (empty($data)) {
            return false;
        }
        $this->updateOwner($developer, $data);
        return true;
    }

Usage Example

Beispiel #1
0
 public function testUpdateBadUrl()
 {
     $output = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface');
     $data = array('blog' => 'knplabs.com');
     $github = $this->getMock('Github\\Client', array('api'));
     $githubDeveloperApi = $this->getMock('Github\\Api\\User', array('show'), array($github));
     $githubDeveloperApi->expects($this->any())->method('show')->with($this->equalTo('lorem'))->will($this->returnValue($data));
     $github->expects($this->any())->method('api')->with('user')->will($this->returnValue($githubDeveloperApi));
     $userEntity = new DeveloperEntity();
     $userEntity->setName('lorem');
     $githubDeveloper = new GithubDeveloper($github, $output);
     $githubDeveloper->update($userEntity);
     $this->assertEquals('http://knplabs.com', $userEntity->getUrl());
 }