Skip to content

Commit

Permalink
Php 8.x constructor style
Browse files Browse the repository at this point in the history
Add note about securing bin arguments
  • Loading branch information
Raphaël Gertz committed Feb 29, 2024
1 parent 3f19569 commit c16e5e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 50 deletions.
27 changes: 2 additions & 25 deletions Filter/CPackFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,17 @@
* {@inheritdoc}
*/
class CPackFilter implements FilterInterface {
//Default bin
private $bin;

//Default compress type
private $compress;

//Twig template filename
private $fileName;

//Twig template line
private $line;

/**
* Setup cpack filter
*
* @xxx compress can be minify or pretty
*/
public function __construct(Source $fileName, int $line, string $bin = 'cpack', string $compress = 'minify') {
//Set fileName
$this->fileName = $fileName;

//Set line
$this->line = $line;

//Set bin
$this->bin = $bin;

//Set compress
$this->compress = $compress;

public function __construct(protected Source $fileName, protected int $line, protected string $bin = 'cpack', protected string $compress = 'minify') {
//Deal with compress
if (!empty($this->compress)) {
//Append minify parameter
if ($this->compress == 'minify') {
//TODO: protect binary call by converting bin to array ?
$this->bin .= ' --minify';
//Unknown compress type
//XXX: default compression is pretty
Expand Down
29 changes: 4 additions & 25 deletions Filter/JPackFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,25 @@
* {@inheritdoc}
*/
class JPackFilter implements FilterInterface {
//Default bin
private $bin;

//Default compress type
private $compress;

//Twig template filename
private $fileName;

//Twig template line
private $line;

/**
* Setup jpack filter
*
* @xxx compress can be clean, shrink, obfuscate or best
*/
public function __construct(Source $fileName, int $line, string $bin = 'jpack', string $compress = 'best') {
//Set fileName
$this->fileName = $fileName;

//Set line
$this->line = $line;

//Set bin
$this->bin = $bin;

//Set compress
$this->compress = $compress;

public function __construct(protected Source $fileName, protected int $line, protected string $bin = 'jpack', protected string $compress = 'best') {
//Deal with compress
if (!empty($this->compress)) {
//Append clean parameter
if ($this->compress == 'clean') {
//TODO: protect binary call by converting bin to array ?
$this->bin .= ' --clean';
//Append shrink parameter
} elseif ($this->compress == 'shrink') {
//TODO: protect binary call by converting bin to array ?
$this->bin .= ' --shrink';
//Append obfuscate parameter
} elseif ($this->compress == 'obfuscate') {
//TODO: protect binary call by converting bin to array ?
$this->bin .= ' --obfuscate';
//Unknown compress type
//XXX: default compression is best
Expand Down

0 comments on commit c16e5e7

Please sign in to comment.