-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jaumarar/process-quotes
Added process of quotes
- Loading branch information
Showing
9 changed files
with
269 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
namespace DevCoder\Processor; | ||
|
||
abstract class AbstractProcessor implements IProcessor | ||
{ | ||
/** | ||
* The value to process | ||
* @var string | ||
*/ | ||
protected $value; | ||
|
||
public function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
namespace DevCoder\Processor; | ||
|
||
class BooleanProcessor extends AbstractProcessor | ||
{ | ||
public function canBeProcessed(): bool | ||
{ | ||
$loweredValue = strtolower($this->value); | ||
|
||
return in_array($loweredValue, ['true', 'false'], true); | ||
} | ||
|
||
public function execute() | ||
{ | ||
return strtolower($this->value) === 'true'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
namespace DevCoder\Processor; | ||
|
||
interface IProcessor | ||
{ | ||
public function __construct(string $value); | ||
|
||
public function canBeProcessed(): bool; | ||
|
||
public function execute(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace DevCoder\Processor; | ||
|
||
class QuotedProcessor extends AbstractProcessor | ||
{ | ||
public function canBeProcessed(): bool | ||
{ | ||
$wrappedByDoubleQuotes = $this->isWrappedByChar($this->value, '"'); | ||
|
||
if ($wrappedByDoubleQuotes) { | ||
return true; | ||
} | ||
|
||
return $this->isWrappedByChar($this->value, '\''); | ||
} | ||
|
||
public function execute() | ||
{ | ||
/** | ||
* Since this function is used for the quote removal | ||
* we don't need mb_substr | ||
*/ | ||
return substr($this->value, 1, -1); | ||
} | ||
|
||
private function isWrappedByChar(string $value, string $char) : bool | ||
{ | ||
return $value[0] === $char && $value[-1] === $char; | ||
} | ||
} |
Oops, something went wrong.