Skip to content

Commit

Permalink
Use laravel validations (#19)
Browse files Browse the repository at this point in the history
* laravel 11 workflow

* fix composer dependencies

* fix composer dependencies

* add back pestphp 1.21

* use laravel native validations

* Fix styling

* use regex to match validation messages in tests

* Fix styling

* updated changelog and cleanup

---------

Co-authored-by: Sowren Sen <[email protected]>
Co-authored-by: sowrensen <[email protected]>
  • Loading branch information
3 people authored Mar 5, 2024
1 parent 7bc13a9 commit 1bf9547
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 197 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.2, 8.1]
laravel: [10.*, 9.*]
php: ["8.3", "8.2", "8.1"]
laravel: ["^11.0", "^10.0", "^9.0"]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
- laravel: "^11.0"
testbench: "9.*"
- laravel: "^10.0"
testbench: "8.*"
- laravel: "^9.0"
testbench: "7.*"
exclude:
- laravel: "^11.0"
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to `svg-avatar-generator` will be documented in this file.

## 1.4.2

- Use laravel validation instead of manually checking configs.
- Added `ConfigValidator` class to define and perform validations.
- Changed modifiers for `$config` and `$extractor` in `SvgAvatarGenerator` class.
- Removed stale exception classes.
- Laravel 11 github workflows.

## 1.4.1

- Laravel 11 support.

## 1.4.0

- Support for custom fonts.
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Optionally, you can publish the config file with:
```bash
php artisan vendor:publish --tag="svg-avatar-generator-config"
```

> ⚠️ You should republish the config file after updating.
> [!WARNING]
> You should republish the config file after updating.
## Usage

Expand Down Expand Up @@ -73,7 +73,8 @@ class User extends Model
}
```

> **Note**: If your accessor is different from the original attribute, you might want to put it in `$appends` array so
> [!NOTE]
> If your accessor is different from the original attribute, you might want to put it in `$appends` array so
> that it loads automatically with your model.
### Override default config
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
"illuminate/contracts": "^9.0 || ^10.0 || ^11.0"
},
"require-dev": {
"nunomaduro/collision": "^6.0",
"orchestra/testbench": "^7.0 || ^8.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"phpunit/phpunit": "^9.5",
"nunomaduro/collision": "^6.0 || ^7.0 || ^8.0",
"orchestra/testbench": "^7.0 || ^8.0 || ^9.0",
"pestphp/pest": "^1.21 || ^2.0",
"pestphp/pest-plugin-laravel": "^1.1 || ^2.0",
"phpunit/phpunit": "^9.5 || ^10.1",
"spatie/laravel-ray": "^1.32"
},
"autoload": {
Expand Down
8 changes: 2 additions & 6 deletions src/Concerns/Tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
namespace Sowren\SvgAvatarGenerator\Concerns;

use Arr;
use Sowren\SvgAvatarGenerator\Exceptions\MissingTextException;
use Sowren\SvgAvatarGenerator\Validators\ConfigValidator;

trait Tool
{
/**
* Extract initials using configured extractor.
*
* @throws MissingTextException
*/
protected function extractInitials(): void
{
if (! $this->text) {
throw MissingTextException::create();
}
ConfigValidator::validate('svg_text', $this->text);

$initials = $this->extractor->extract($this->text);
$this->setInitials($initials);
Expand Down
11 changes: 0 additions & 11 deletions src/Exceptions/InvalidCornerRadius.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/Exceptions/InvalidFontSizeException.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/Exceptions/InvalidGradientRotationException.php

This file was deleted.

13 changes: 0 additions & 13 deletions src/Exceptions/InvalidGradientStopException.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/Exceptions/InvalidSvgSizeException.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/Exceptions/InvalidUrlException.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/Exceptions/MissingTextException.php

This file was deleted.

34 changes: 33 additions & 1 deletion src/Facades/Svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,45 @@
namespace Sowren\SvgAvatarGenerator\Facades;

use Illuminate\Support\Facades\Facade;
use Sowren\SvgAvatarGenerator\Enums\FontWeight;
use Sowren\SvgAvatarGenerator\Enums\Shape;
use Sowren\SvgAvatarGenerator\SvgAvatarGenerator;

/**
* @method static SvgAvatarGenerator for(string $text)
* @method static string getInitials()
* @method static int getSize()
* @method static SvgAvatarGenerator setSize(int $size)
* @method static Shape getShape()
* @method static SvgAvatarGenerator asCircle()
* @method static SvgAvatarGenerator asRectangle()
* @method static int getCornerRadius()
* @method static SvgAvatarGenerator setCornerRadius(int $radius)
* @method static string|null getCustomFontUrl()
* @method static SvgAvatarGenerator setCustomFontUrl(?string $url = null)
* @method static string|null getFontFamily()
* @method static SvgAvatarGenerator setFontFamily(?string $name = null)
* @method static int getFontSize()
* @method static SvgAvatarGenerator setFontSize(int $fontSize)
* @method static FontWeight getFontWeight()
* @method static SvgAvatarGenerator setFontWeight(FontWeight $fontWeight)
* @method static string getForeground()
* @method static SvgAvatarGenerator setForeground(string $color)
* @method static int getGradientRotation()
* @method static SvgAvatarGenerator setGradientRotation(int $angle)
* @method static array getGradientColors()
* @method static SvgAvatarGenerator setGradientColors(string|array ...$colors)
* @method static array getGradientStops()
* @method static SvgAvatarGenerator setGradientStops(int|float ...$offsets)
* @method static array getGradientSet()
* @method static \Sowren\SvgAvatarGenerator\Svg render()
* @method static string toUrl()
*
* @see \Sowren\SvgAvatarGenerator\SvgAvatarGenerator
*/
class Svg extends Facade
{
protected static function getFacadeAccessor()
protected static function getFacadeAccessor(): string
{
return \Sowren\SvgAvatarGenerator\SvgAvatarGenerator::class;
}
Expand Down
15 changes: 0 additions & 15 deletions src/Http/Controllers/SvgController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Sowren\SvgAvatarGenerator\Exceptions\InvalidCornerRadius;
use Sowren\SvgAvatarGenerator\Exceptions\InvalidFontSizeException;
use Sowren\SvgAvatarGenerator\Exceptions\InvalidGradientRotationException;
use Sowren\SvgAvatarGenerator\Exceptions\InvalidGradientStopException;
use Sowren\SvgAvatarGenerator\Exceptions\InvalidSvgSizeException;
use Sowren\SvgAvatarGenerator\Exceptions\InvalidUrlException;
use Sowren\SvgAvatarGenerator\Exceptions\MissingTextException;
use Sowren\SvgAvatarGenerator\SvgAvatarGenerator;

class SvgController extends Controller
Expand All @@ -23,14 +16,6 @@ public function __construct()

/**
* Generate an SVG and send it as an HTTP response.
*
* @throws InvalidCornerRadius
* @throws InvalidUrlException
* @throws MissingTextException
* @throws InvalidSvgSizeException
* @throws InvalidFontSizeException
* @throws InvalidGradientStopException
* @throws InvalidGradientRotationException
*/
public function __invoke(Request $request): Response
{
Expand Down
Loading

0 comments on commit 1bf9547

Please sign in to comment.