Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix attributes type #66

Merged
merged 3 commits into from
Jan 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Attribute/Duration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class Duration implements AttributeInterface
private $milliseconds;

/**
* @param $duration
* @param string|int $duration
*/
public function __construct($duration)
{
$this->milliseconds = $duration;
$this->milliseconds = (int) $duration;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Attribute/Rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Rate implements AttributeInterface
use DumpTrait;

/**
* @var int
* @var float
*/
private $absoluteValue;

Expand All @@ -19,17 +19,17 @@ class Rate implements AttributeInterface
private $textValue;

/**
* @param $absoluteValue
* @param $textValue
* @param string|float $absoluteValue
* @param string $textValue
*/
public function __construct($absoluteValue, $textValue)
{
$this->absoluteValue = $absoluteValue;
$this->absoluteValue = (float) $absoluteValue;
$this->textValue = $textValue;
}

/**
* @return int
* @return float
*/
public function getAbsoluteValue()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Attribute/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class Size implements AttributeInterface
private $bit;

/**
* @param int $size
* @param string|int $size
*/
public function __construct($size)
{
$this->bit = $size;
$this->bit = (int) $size;
}

/**
Expand Down
15 changes: 9 additions & 6 deletions test/Attribute/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public function testCover()

public function testDuration()
{
$duration = new Duration(1000);
$this->assertEquals(1000, $duration->getMilliseconds());
$duration = new Duration('1000');
$this->assertSame(1000, $duration->getMilliseconds());
$this->assertTrue(is_int($duration->getMilliseconds()));
$this->assertSame('1000', (string) $duration);
}

Expand All @@ -34,16 +35,18 @@ public function testMode()

public function testRate()
{
$rate = new Rate(15555, '15.55 Mo');
$this->assertEquals(15555, $rate->getAbsoluteValue());
$rate = new Rate('15555', '15.55 Mo');
$this->assertSame(15555.0, $rate->getAbsoluteValue());
$this->assertTrue(is_float($rate->getAbsoluteValue()));
$this->assertEquals('15.55 Mo', $rate->getTextValue());
$this->assertSame('15.55 Mo', (string) $rate);
}

public function testSize()
{
$size = new Size(42);
$this->assertEquals(42, $size->getBit());
$size = new Size('42');
$this->assertSame(42, $size->getBit());
$this->assertTrue(is_int($size->getBit()));
$this->assertSame('42', (string) $size);
}
}