Skip to content

Commit

Permalink
Merge pull request #2 from jedkirby/feature/php-cs
Browse files Browse the repository at this point in the history
PHP Code Styling
  • Loading branch information
jedkirby committed Jan 7, 2017
2 parents dbec93c + 8ab2ed0 commit 657c16c
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 47 deletions.
15 changes: 15 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once __DIR__ . '/vendor/jedkirby/php-cs/src/Config.php';

use PhpCsFixer\Finder;
use Jedkirby\PhpCs\Config;

$finder = Finder::create();
$finder->in(__DIR__ . '/src');
$finder->in(__DIR__ . '/tests');

$config = new Config();
$config->setFinder($finder);

return $config;
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"satooshi/php-coveralls": "^1.0"
"satooshi/php-coveralls": "^1.0",
"jedkirby/php-cs": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 0 additions & 5 deletions src/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

abstract class AbstractEntity implements EntityInterface
{

/**
* @var array
*/
Expand All @@ -23,11 +22,9 @@ public function __construct(array $data = [])

/**
* @throws RequiredPropertyException
* @return void
*/
private function validate()
{

$requiredProperties = $this->getRequiredProperties();
$missingProperties = array_diff(
$requiredProperties,
Expand All @@ -41,7 +38,5 @@ private function validate()
get_called_class()
));
}

}

}
2 changes: 0 additions & 2 deletions src/Entity/EntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

interface EntityInterface
{

/**
* Return properties to validate on loading of the entity.
*
Expand All @@ -25,5 +24,4 @@ public function getSearchText();
* @return string
*/
public function getHtml();

}
1 change: 0 additions & 1 deletion src/Entity/Exception/RequiredPropertyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class RequiredPropertyException extends Exception
{

}
8 changes: 3 additions & 5 deletions src/Entity/Hashtag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@

class Hashtag extends AbstractEntity
{

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getRequiredProperties()
{
return ['text'];
}

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getSearchText()
{
return $this->data['text'];
}

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getHtml()
{
Expand All @@ -32,5 +31,4 @@ public function getHtml()
$this->data['text']
);
}

}
8 changes: 3 additions & 5 deletions src/Entity/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@

class Url extends AbstractEntity
{

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getRequiredProperties()
{
return ['url', 'display_url'];
}

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getSearchText()
{
return $this->data['url'];
}

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getHtml()
{
Expand All @@ -32,5 +31,4 @@ public function getHtml()
$this->data['display_url']
);
}

}
8 changes: 3 additions & 5 deletions src/Entity/UserMention.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@

class UserMention extends AbstractEntity
{

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getRequiredProperties()
{
return ['screen_name'];
}

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getSearchText()
{
return $this->data['screen_name'];
}

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getHtml()
{
Expand All @@ -32,5 +31,4 @@ public function getHtml()
$this->data['screen_name']
);
}

}
6 changes: 1 addition & 5 deletions src/Tweet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class Tweet
{

/**
* @var string
*/
Expand All @@ -30,7 +29,7 @@ class Tweet
* @param array $urls
* @param array $mentions
* @param array $hashtags
*
*
* @return Tweet
*/
public static function make($text, array $urls = [], array $mentions = [], array $hashtags = [])
Expand Down Expand Up @@ -59,7 +58,6 @@ private function __construct($text, array $urls = [], array $mentions = [], arra
*/
public function linkify()
{

$entities = [];

foreach ($this->hashtags as $hashtag) {
Expand All @@ -84,7 +82,5 @@ public function linkify()
}

return $text;

}

}
6 changes: 2 additions & 4 deletions tests/Entity/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

class EntityTest extends TestCase
{

/**
* @test
* @expectedException Jedkirby\TweetEntityLinker\Entity\Exception\RequiredPropertyException
* @expectedException \Jedkirby\TweetEntityLinker\Entity\Exception\RequiredPropertyException
*/
public function itMustHaveRequiredProperties()
{
Expand All @@ -25,5 +24,4 @@ public function itDoesNotNeedToHaveRequiredProperties()
{
$entity = new NoRequiredProperties();
}

}
}
8 changes: 3 additions & 5 deletions tests/Entity/Fixtures/InvalidProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,27 @@

class InvalidProperties extends AbstractEntity
{

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getRequiredProperties()
{
return ['missing', 'required'];
}

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getSearchText()
{
return '';
}

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getHtml()
{
return '';
}

}
8 changes: 3 additions & 5 deletions tests/Entity/Fixtures/NoRequiredProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,27 @@

class NoRequiredProperties extends AbstractEntity
{

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getRequiredProperties()
{
return [];
}

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getSearchText()
{
return '';
}

/**
* {@inhertDoc}
* {@inhertDoc}.
*/
public function getHtml()
{
return '';
}

}
4 changes: 0 additions & 4 deletions tests/TweetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class TweetTest extends TestCase
{

/**
* @param string $endpoint
*
Expand Down Expand Up @@ -35,7 +34,6 @@ protected function getSampleApiResponse($endpoint)
*/
protected function getSampleTweet($endpoint)
{

$response = $this->getSampleApiResponse($endpoint);

return Tweet::make(
Expand All @@ -44,7 +42,6 @@ protected function getSampleTweet($endpoint)
$response['entities']['user_mentions'],
$response['entities']['hashtags']
);

}

/**
Expand Down Expand Up @@ -90,5 +87,4 @@ public function itParsesAllEntitiesCorrectly()
'This tweet has it all, it has got the links <a href="https://t.co/qeSnkprYiP" target="_blank">jedkirby.com</a> and <a href="https://t.co/Ed4omjYs" target="_blank">google.co.uk</a>, it has the hashtags #<a href="https://twitter.com/hashtag/Hashtag" target="_blank">Hashtag</a> and #<a href="https://twitter.com/hashtag/Another" target="_blank">Another</a>, and finally the user mentions for @<a href="https://twitter.com/jedkirby" target="_blank">jedkirby</a> and @<a href="https://twitter.com/google" target="_blank">google</a>.'
);
}

}

0 comments on commit 657c16c

Please sign in to comment.