Skip to content

Commit

Permalink
feat: 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bepsvpt committed Feb 9, 2024
1 parent db928b5 commit 47641d4
Show file tree
Hide file tree
Showing 42 changed files with 1,208 additions and 291 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.php]
indent_size = 4
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto eol=lf

*.md diff=markdown
*.php diff=php
12 changes: 5 additions & 7 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ name: Testing

on:
push:
pull_request:
schedule:
# run tests on every week Monday
- cron: '0 0 * * 1'
- cron: '0 0 * * 1' # run tests on every week Monday

jobs:
static_analysis:
Expand All @@ -19,14 +17,14 @@ jobs:
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.3'
coverage: xdebug

- name: Get composer cache directory
run: echo "COMPOSER_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_DIR }}
key: ${{ runner.os }}-composer-static-analysis-${{ hashFiles('**/composer.json') }}
Expand All @@ -45,7 +43,7 @@ jobs:
run: composer normalize --dry-run

- name: Run static analysis
run: vendor/bin/phpstan --verbose
run: vendor/bin/phpstan --memory-limit=-1 --verbose

- name: Run coding style checker
run: vendor/bin/pint --verbose --test
Expand Down Expand Up @@ -82,7 +80,7 @@ jobs:
run: echo "COMPOSER_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_DIR }}
key: ${{ runner.os }}-composer-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.json') }}
Expand Down
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/.fleet
/.idea
/build
/.vscode
/coverage
/vendor
.php_cs.cache
.DS_Store
.phpunit.result.cache
clover.xml
composer.phar
composer.lock
Thumbs.db
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) BePsvPT
Copyright (c) bepsvpt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
53 changes: 53 additions & 0 deletions artisan
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env php
<?php

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any of our classes manually. It's great to relax.
|
*/

require __DIR__.'/vendor/autoload.php';

$app = require_once __DIR__.'/vendor/orchestra/testbench-core/laravel/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/

$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);

$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);

/*
|--------------------------------------------------------------------------
| Shutdown The Application
|--------------------------------------------------------------------------
|
| Once Artisan has finished running, we will fire off the shutdown events
| so that any final work may be done by the application before we shut
| down the process. This is the last thing to happen to the request.
|
*/

$kernel->terminate($input, $status);

exit($status);
23 changes: 14 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
"authors": [
{
"name": "bepsvpt",
"email": "[email protected]"
"email": "[email protected]"
}
],
"homepage": "https://github.com/bepsvpt/blurhash",
"require": {
"php": "^8.0",
"ext-gd": "*",
"illuminate/support": "^8.0 || ^9.0 || ^10.0",
"intervention/image": "^2.7"
"php": "^8.1",
"ext-exif": "*",
"illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.39",
"ergebnis/composer-normalize": "^2.42",
"jcupitt/vips": "^2.3",
"larastan/larastan": "^2.8",
"laravel/pint": "^1.13",
"orchestra/testbench": "^6.38 || ^7.35 || ^8.15",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.6 || ^10.4"
"orchestra/testbench": "^6.42 || ^7.40 || ^8.21",
"phpunit/phpunit": "^9.6 || ^10.5"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down Expand Up @@ -56,5 +56,10 @@
"Bepsvpt\\Blurhash\\BlurHashServiceProvider"
]
}
},
"suggest": {
"ext-gd": "Required to use GD driver.",
"ext-imagick": "Required to use Imagick driver.",
"jcupitt/vips": "Required to use php-vips driver."
}
}
31 changes: 18 additions & 13 deletions config/blurhash.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@
return [

/*
* Components picked from image x and y axis.
* The image driver is used for encoding and decoding blurhash.
*
* The more components you pick, the more information
* is retained in the placeholder, but the longer the
* BlurHash string will be. Also, it doesn't always
* look good with too many components.
* Supported drivers include "gd", "imagick", and "php-vips".
*/

'driver' => 'gd',

/*
* Components are selected from the image's x and y axis.
*
* Valid value is from 1 to 9.
* Choosing more components means the placeholder will
* retain more information, but it also makes the
* BlurHash string longer. However, having too many
* components doesn't always result in a better look.
*
* The valid range for values is from 1 to 9.
*/

'components-x' => 4,

'components-y' => 3,

/*
* Resize image max width.
*
* When encoding the image, image will resize to
* small one to optimize performance. It is not
* recommend to set the value larger than 256.
*
* When encoding the image, it will resize to a smaller
* version to enhance performance. It's not recommended
* to set the max width and height values larger than 256.
*/

'resized-image-max-width' => 64,
'resized-max-size' => 64,

];
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
includes:
- vendor/larastan/larastan/extension.neon

parameters:
level: max

Expand Down
22 changes: 20 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
executionOrder="random"
testdox="true"
>
<source>
<include>
<directory>src</directory>
</include>
</source>
<testsuites>
<testsuite name="BlurHash Test">
<directory>./tests</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="coverage"/>
</report>
</coverage>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="error_reporting" value="-1"/>
<ini name="log_errors_max_len" value="0"/>
<ini name="xdebug.show_exception_trace" value="0"/>
<ini name="zend.assertions" value="1"/>
<ini name="assert.exception" value="1"/>
</php>
</phpunit>
11 changes: 0 additions & 11 deletions pint.json

This file was deleted.

30 changes: 12 additions & 18 deletions src/Base83.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Base83
/**
* Base 63 encoder/decoder character index map.
*
* @var array<int|string, int>
* @var array<int|string, int<0, 82>>
*/
protected static array $indexMap = [
'0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4,
Expand All @@ -46,30 +46,24 @@ class Base83
*/
public static function encode(int $value, int $length): string
{
static $powOf83 = [1, 83, 6889, 571787, 47458321];
$powOf83 = [1, 83, 6889, 571787, 47458321];

$result = '';

for ($i = 1; $i <= $length; ++$i) {
$digit = intdiv($value, $powOf83[$length - $i]) % 83;

$result .= self::$characters[$digit];
}

return $result;
return array_reduce(
range($length - 1, 0),
fn (string $carry, int $idx) => $carry.self::$characters[intdiv($value, $powOf83[$idx]) % 83],
'',
);
}

/**
* Decode a string to integer.
*/
public static function decode(string $encoded): int
{
$result = 0;

foreach (str_split($encoded) as $char) {
$result = $result * 83 + static::$indexMap[$char];
}

return $result;
return array_reduce(
str_split($encoded),
fn (int $carry, string $char) => $carry * 83 + static::$indexMap[$char],
0,
);
}
}
Loading

0 comments on commit 47641d4

Please sign in to comment.