Skip to content

Commit

Permalink
refactor: adapter change
Browse files Browse the repository at this point in the history
  • Loading branch information
ddevsr committed Apr 4, 2023
1 parent 85e3af2 commit b4ef054
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,22 @@
namespace PHPDevsr\Minifyku\Adapters;

use MatthiasMullie\Minify\CSS as MinifyCSS;
use MatthiasMullie\Minify\JS as MinifyJS;
use PHPDevsr\Minifyku\Exceptions\MinifykuException;

class MinifykuAdapter implements AdapterInterface
class MinifykuCSSAdapter implements AdapterInterface
{
/**
* Adapter object.
*
* @var MinifyCSS|MinifyJS
* @var object
*/
protected $adapter;

/**
* __construct
*/
public function __construct(string $type = 'css')
public function __construct()
{
if (! in_array($type, ['js', 'css'], true)) {
throw MinifykuException::forWrongFileExtension($type);
}

if ($type === 'js') {
$this->adapter = new MinifyJS();
}

if ($type === 'css') {
$this->adapter = new MinifyCSS();
}
$this->adapter = new MinifyCSS();
}

/**
Expand Down
43 changes: 43 additions & 0 deletions src/Adapters/MinifykuJSAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace PHPDevsr\Minifyku\Adapters;

use MatthiasMullie\Minify\JS as MinifyJS;

class MinifykuJSAdapter implements AdapterInterface
{
/**
* Adapter object.
*
* @var object
*/
protected $adapter;

/**
* __construct
*/
public function __construct()
{
$this->adapter = new MinifyJS();
}

/**
* Add file
*
* @param string $file File name
*/
public function add($file)
{
$this->adapter->add($file);
}

/**
* Minify file
*
* @param string $file File name
*/
public function minify(string $file)
{
return $this->adapter->minify($file);
}
}
8 changes: 5 additions & 3 deletions src/Minifyku.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace PHPDevsr\Minifyku;

use PHPDevsr\Minifyku\Adapters\MinifykuAdapter;
use PHPDevsr\Minifyku\Adapters\MinifykuCSSAdapter;
use PHPDevsr\Minifyku\Adapters\MinifykuJSAdapter;
use PHPDevsr\Minifyku\Config\Minifyku as MinifykuConfig;
use PHPDevsr\Minifyku\Exceptions\MinifykuException;

Expand Down Expand Up @@ -272,10 +273,11 @@ protected function deployFiles(string $fileType, array $assets, string $dir, ?st
$minDir = $dir;
}

$results = [];
$classMinify = $fileType === 'js' ? MinifykuJSAdapter::class : MinifykuCSSAdapter::class;
$results = [];

foreach ($assets as $asset => $files) {
$class = new MinifykuAdapter($fileType);
$class = new $classMinify();

foreach ($files as $file) {
$class->add($dir . DIRECTORY_SEPARATOR . $file);
Expand Down

0 comments on commit b4ef054

Please sign in to comment.