Skip to content

Commit

Permalink
refactor: single quote strings, short syntax arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
adevade committed Jan 31, 2023
1 parent b9ff408 commit d53d680
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
11 changes: 6 additions & 5 deletions src/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class UrlBuilder
100, 116, 134, 156, 182, 210, 244, 282,
328, 380, 442, 512, 594, 688, 798, 926,
1074, 1246, 1446, 1678, 1946, 2258, 2618,
3038, 3524, 4088, 4742, 5500, 6380, 7400, 8192];
3038, 3524, 4088, 4742, 5500, 6380, 7400, 8192,
];

// define class constants
// should be private; but visibility modifiers are not supported php version <7.1
Expand Down Expand Up @@ -133,12 +134,12 @@ public function createSrcSet($path, $params = [], $options = [])
* @return int[] $resolutions An array of integer values.
*/
public function targetWidths(
$start=self::MIN_WIDTH,
$stop=self::MAX_WIDTH,
$tol=self::SRCSET_WIDTH_TOLERANCE
$start = self::MIN_WIDTH,
$stop = self::MAX_WIDTH,
$tol = self::SRCSET_WIDTH_TOLERANCE
) {
if ($start === $stop) {
return array((int) $start);
return [(int) $start];
}

Validator::validateMinMaxTol($start, $stop, $tol);
Expand Down
9 changes: 5 additions & 4 deletions tests/UrlBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class UrlBuilderTest extends TestCase
100, 116, 135, 156, 181, 210, 244, 283,
328, 380, 441, 512, 594, 689, 799, 927,
1075, 1247, 1446, 1678, 1946, 2257, 2619,
3038, 3524, 4087, 4741, 5500, 6380, 7401, 8192];
3038, 3524, 4087, 4741, 5500, 6380, 7401, 8192,
];

public function testURLBuilderRaisesExceptionOnNoDomain()
{
Expand Down Expand Up @@ -239,10 +240,10 @@ public function testNoParametersGeneratesSrcsetPairs()
public function testCustomSrcsetPairs()
{
// Test custom srcset pairs within ranges.
$builder = new UrlBuilder("demos.imgix.net", true, false);
$opts = array('start' => 328, 'stop' => 328);
$actual = $builder->createSrcSet($path="image.jpg", $params=array(), $options=$opts);
$expected = 'https://demos.imgix.net/image.jpg?ixlib=php-'. self::PACKAGE_VERSION . '&w=328 328w';
$builder = new UrlBuilder('demos.imgix.net', true, false);
$opts = ['start' => 328, 'stop' => 328];
$actual = $builder->createSrcSet($path = 'image.jpg', $params = [], $options = $opts);
$this->assertEquals($expected, $actual);

$builder = new UrlBuilder('demos.imgix.net', true, false);
Expand Down
24 changes: 12 additions & 12 deletions tests/UrlHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public function testHelperFormatPathWithNoPath()

public function testHelperFormatPathWithSimplePath()
{
$path = "dog.jpg";
$uh = new URLHelper("test.imgix.net", $path);
$path = 'dog.jpg';
$uh = new URLHelper('test.imgix.net', $path);

$this->assertEquals($uh->formatPath($path), '/'.$path);
}
Expand Down Expand Up @@ -146,19 +146,19 @@ public function testHelperBuildSignedURLWithHashSetterParamsHttps()

public function testHelperBuildSignedURLWithNullHashSetterParams()
{
$uh = new URLHelper("imgix-library-secure-test-source.imgix.net", "dog.jpg", "https", "EHFQXiZhxP4wA2c4");
$uh->setParameter("w", 500);
$this->assertEquals("https://imgix-library-secure-test-source.imgix.net/dog.jpg?w=500&s=e4eb402d12bbdf267bf0fc5588170d56", $uh->getURL());
$uh->setParameter("w", null);
$this->assertEquals("https://imgix-library-secure-test-source.imgix.net/dog.jpg?s=2b0bc99b1042e3c1c9aae6598acc3def", $uh->getURL());
$uh = new URLHelper('imgix-library-secure-test-source.imgix.net', 'dog.jpg', 'https', 'EHFQXiZhxP4wA2c4');
$uh->setParameter('w', 500);
$this->assertEquals('https://imgix-library-secure-test-source.imgix.net/dog.jpg?w=500&s=e4eb402d12bbdf267bf0fc5588170d56', $uh->getURL());
$uh->setParameter('w', null);
$this->assertEquals('https://imgix-library-secure-test-source.imgix.net/dog.jpg?s=2b0bc99b1042e3c1c9aae6598acc3def', $uh->getURL());
}

public function testHelperBuildSignedURLWithHashDeleterParams()
{
$uh = new URLHelper("imgix-library-secure-test-source.imgix.net", "dog.jpg", "https", "EHFQXiZhxP4wA2c4");
$uh->setParameter("w", 500);
$this->assertEquals("https://imgix-library-secure-test-source.imgix.net/dog.jpg?w=500&s=e4eb402d12bbdf267bf0fc5588170d56", $uh->getURL());
$uh->deleteParameter("w");
$this->assertEquals("https://imgix-library-secure-test-source.imgix.net/dog.jpg?s=2b0bc99b1042e3c1c9aae6598acc3def", $uh->getURL());
$uh = new URLHelper('imgix-library-secure-test-source.imgix.net', 'dog.jpg', 'https', 'EHFQXiZhxP4wA2c4');
$uh->setParameter('w', 500);
$this->assertEquals('https://imgix-library-secure-test-source.imgix.net/dog.jpg?w=500&s=e4eb402d12bbdf267bf0fc5588170d56', $uh->getURL());
$uh->deleteParameter('w');
$this->assertEquals('https://imgix-library-secure-test-source.imgix.net/dog.jpg?s=2b0bc99b1042e3c1c9aae6598acc3def', $uh->getURL());
}
}

0 comments on commit d53d680

Please sign in to comment.