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

style: formatting and remove dead code #96

Merged
merged 4 commits into from
Dec 5, 2022
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
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: 2.1 # Use 2.1 to enable using orbs and other features.
orbs:

orbs:
php: circleci/[email protected]

jobs:
test:
parameters:
version:
version:
default: "8.0"
description: PHP version to install
type: string
Expand All @@ -27,15 +27,15 @@ jobs:
equal: [ "8.1", <<parameters.version>> ]
steps:
- run: composer update

# install deps
- run: composer install

# run tests
- run:
- run:
name: PHPUnit Tests
command: vendor/bin/phpunit --bootstrap src/autoload.php tests

workflows:
version: 2
test:
Expand Down
20 changes: 10 additions & 10 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ modification, are permitted provided that the following conditions are met:
this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ $builder = new UrlBuilder("demos.imgix.net", true, "my-key", false);
echo $builder->createSrcSet("image.png");
```

The above will produce the following srcset attribute value which can then be served to the client:
The above will produce the following srcset attribute value which can then be served to the client:

``` html
https://demos.imgix.net/image.png?w=100&s=e415797545a77a9d2842dedcfe539c9a 100w,
Expand Down
26 changes: 10 additions & 16 deletions src/Imgix/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Imgix;

use Imgix\Validator;
sherwinski marked this conversation as resolved.
Show resolved Hide resolved

class UrlBuilder {

private $currentVersion = "3.3.1";
Expand All @@ -27,31 +25,27 @@ class UrlBuilder {
const MAX_WIDTH = 8192;
const SRCSET_WIDTH_TOLERANCE = 0.08;

// constants cannot be dynamically assigned; keeping as a class variable instead
private $targetWidths;
sherwinski marked this conversation as resolved.
Show resolved Hide resolved

public function __construct($domain, $useHttps = true, $signKey = "", $includeLibraryParam = true) {

if (!is_string($domain)) {
throw new \InvalidArgumentException("UrlBuilder must be passed a string domain");
}

$this->domain = $domain;
$this->validateDomain($this->domain);
$this->validateDomain($this->domain);

$this->useHttps = $useHttps;
$this->signKey = $signKey;
$this->includeLibraryParam = $includeLibraryParam;
$this->targetWidths = $this->targetWidths();
sherwinski marked this conversation as resolved.
Show resolved Hide resolved
}

private function validateDomain($domain) {
$DOMAIN_PATTERN = "/^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/";

if(!preg_match($DOMAIN_PATTERN, $domain)) {
throw new \InvalidArgumentException('Domain must be passed in as fully-qualified ' .
throw new \InvalidArgumentException('Domain must be passed in as fully-qualified ' .
'domain name and should not include a protocol or any path element, i.e. ' .
'"example.imgix.net".');
'"example.imgix.net".');
}
}

Expand Down Expand Up @@ -87,7 +81,7 @@ public function createSrcSet($path, $params=array(), $options=array()) {
Validator::validateWidths($widthsArray);
return $this->createSrcSetPairs($path, $params=$params, $widthsArray);
}

$_start = isset($options['start']) ? $options['start'] : self::MIN_WIDTH;
$_stop = isset($options['stop']) ? $options['stop'] : self::MAX_WIDTH;
$_tol = isset($options['tol']) ? $options['tol'] : self::SRCSET_WIDTH_TOLERANCE;
Expand All @@ -96,8 +90,8 @@ public function createSrcSet($path, $params=array(), $options=array()) {

if ($this->isDpr($params)) {
return $this->createDPRSrcSet(
$path=$path,
$params=$params,
$path=$path,
$params=$params,
$disableVariableQuality=$_disableVariableQuality);
}
else {
Expand All @@ -108,17 +102,17 @@ public function createSrcSet($path, $params=array(), $options=array()) {

/**
* Generate a list of target widths.
*
*
* This function generates an array of target widths used to
* width-describe image candidate strings (URLs) within a
* srcset attribute.
*
*
* This function returns an array of integer values that denote
* image target widths. This array begins with `$start`
* and ends with `$stop`. The `$tol` or tolerance value dictates
* the amount of tolerable width variation between each width
* in the range of values that lie between `$start` and `$stop`.
*
*
* @param int $start Starting minimum width value.
* @param int $stop Stopping maximum width value.
* @param int $tol Tolerable amount of width variation.
Expand Down Expand Up @@ -147,7 +141,7 @@ public function targetWidths(
if (end($resolutions) < $stop) {
array_push($resolutions, (int) $stop);
}

return $resolutions;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Imgix/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static function validateMinWidth($start) {

public static function validateMaxWidth($end) {
if ($end < 0) {
throw new \InvalidArgumentException("`stop` width value must be greater than zero");
throw new \InvalidArgumentException("`stop` width value must be greater than zero");
}
}

Expand All @@ -25,7 +25,7 @@ public static function validateRange($start, $stop) {

// Ensure that the range is valid, ie. `begin <= end`.
if ($start > $stop) {
throw new \InvalidArgumentException("`start` width value must be less than `stop` width value");
throw new \InvalidArgumentException("`start` width value must be less than `stop` width value");
}
}

Expand Down Expand Up @@ -56,4 +56,4 @@ public static function validateWidths($widths) {
}
}
}
}
}
3 changes: 1 addition & 2 deletions src/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

$fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName . $className . '.php';
//$fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName . $namespace . '.php';

if (is_file($fileName)) {
require $fileName;

Expand All @@ -23,4 +23,3 @@

return false;
});

2 changes: 1 addition & 1 deletion tests/Imgix/Tests/PathEncodingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ public function testUnicodeEncoding() {
$url);
}

}
}
8 changes: 4 additions & 4 deletions tests/Imgix/Tests/ReadMeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ReadMeTest extends \PHPUnit\Framework\TestCase {
public function testFixedWithImages() {
$builder = new UrlBuilder("demos.imgix.net", true, "my-key", false);
$actual = $builder->createSrcSet("image.png", array("h"=>800, "ar"=>"3:2", "fit"=>"crop"));
$expected =
$expected =
"https://demos.imgix.net/image.png?ar=3%3A2&dpr=1&fit=crop&h=800&q=75&s=b6b4a327a9e5a9ce5c9251b736c98633 1x,
https://demos.imgix.net/image.png?ar=3%3A2&dpr=2&fit=crop&h=800&q=50&s=4f96c2dffa682c081ba9b994c49222cc 2x,
https://demos.imgix.net/image.png?ar=3%3A2&dpr=3&fit=crop&h=800&q=35&s=7b2a069e769cfeaf9e6dbb4679aea2bc 3x,
Expand Down Expand Up @@ -51,7 +51,7 @@ public function testFluidWidthRanges() {
$builder = new UrlBuilder("demo.imgix.net", true, "", false);
$opts = array('start' => 500, 'stop' => 2000);
$actual = $builder->createSrcSet($path="image.jpg", $params=array(), $options=$opts);
$expected =
$expected =
'https://demo.imgix.net/image.jpg?w=500 500w,
https://demo.imgix.net/image.jpg?w=580 580w,
https://demo.imgix.net/image.jpg?w=673 673w,
Expand All @@ -71,7 +71,7 @@ public function testFluidWidthRangesTolerance() {
$builder = new UrlBuilder("demo.imgix.net", true, "", false);
$opts = array('start' => 100, 'stop' => 384, 'tol' => 0.20);
$actual = $builder->createSrcSet($path="image.jpg", $params=array(), $options=$opts);
$expected =
$expected =
'https://demo.imgix.net/image.jpg?w=100 100w,
https://demo.imgix.net/image.jpg?w=140 140w,
https://demo.imgix.net/image.jpg?w=196 196w,
Expand All @@ -80,4 +80,4 @@ public function testFluidWidthRangesTolerance() {

$this->assertEquals($expected, $actual);
}
}
}
Loading