Refactoring
This commit is contained in:
28
lib/composer/vendor/consolidation/output-formatters/src/Validate/ValidDataTypesInterface.php
vendored
Normal file
28
lib/composer/vendor/consolidation/output-formatters/src/Validate/ValidDataTypesInterface.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Consolidation\OutputFormatters\Validate;
|
||||
|
||||
/**
|
||||
* Formatters may implement ValidDataTypesInterface in order to indicate
|
||||
* exactly which formats they support. The validDataTypes method can be
|
||||
* called to retrieve a list of data types useful in providing hints in
|
||||
* exception messages about which data types can be used with the formatter.
|
||||
*
|
||||
* Note that it is OPTIONAL for formatters to implement this interface.
|
||||
* If a formatter implements only ValidationInterface, then clients that
|
||||
* request the formatter via FormatterManager::write() will still get a list
|
||||
* (via an InvalidFormatException) of all of the formats that are usable
|
||||
* with the provided data type. Implementing ValidDataTypesInterface is
|
||||
* benefitial to clients who instantiate a formatter directly (via `new`).
|
||||
*
|
||||
* Formatters that implement ValidDataTypesInterface may wish to use
|
||||
* ValidDataTypesTrait.
|
||||
*/
|
||||
interface ValidDataTypesInterface extends ValidationInterface
|
||||
{
|
||||
/**
|
||||
* Return the list of data types acceptable to this formatter
|
||||
*
|
||||
* @return \ReflectionClass[]
|
||||
*/
|
||||
public function validDataTypes();
|
||||
}
|
||||
34
lib/composer/vendor/consolidation/output-formatters/src/Validate/ValidDataTypesTrait.php
vendored
Normal file
34
lib/composer/vendor/consolidation/output-formatters/src/Validate/ValidDataTypesTrait.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Consolidation\OutputFormatters\Validate;
|
||||
|
||||
/**
|
||||
* Provides a default implementation of isValidDataType.
|
||||
*
|
||||
* Users of this trait are expected to implement ValidDataTypesInterface.
|
||||
*/
|
||||
trait ValidDataTypesTrait
|
||||
{
|
||||
/**
|
||||
* Return the list of data types acceptable to this formatter
|
||||
*
|
||||
* @return \ReflectionClass[]
|
||||
*/
|
||||
public abstract function validDataTypes();
|
||||
|
||||
/**
|
||||
* Return the list of data types acceptable to this formatter
|
||||
*/
|
||||
public function isValidDataType(\ReflectionClass $dataType)
|
||||
{
|
||||
return array_reduce(
|
||||
$this->validDataTypes(),
|
||||
function ($carry, $supportedType) use ($dataType) {
|
||||
return
|
||||
$carry ||
|
||||
($dataType->getName() == $supportedType->getName()) ||
|
||||
($dataType->isSubclassOf($supportedType->getName()));
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
28
lib/composer/vendor/consolidation/output-formatters/src/Validate/ValidationInterface.php
vendored
Normal file
28
lib/composer/vendor/consolidation/output-formatters/src/Validate/ValidationInterface.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Consolidation\OutputFormatters\Validate;
|
||||
|
||||
/**
|
||||
* Formatters may implement ValidationInterface in order to indicate
|
||||
* whether a particular data structure is supported. Any formatter that does
|
||||
* not implement ValidationInterface is assumed to only operate on arrays,
|
||||
* or data types that implement SimplifyToArrayInterface.
|
||||
*/
|
||||
interface ValidationInterface
|
||||
{
|
||||
/**
|
||||
* Return true if the specified format is valid for use with
|
||||
* this formatter.
|
||||
*/
|
||||
public function isValidDataType(\ReflectionClass $dataType);
|
||||
|
||||
/**
|
||||
* Throw an IncompatibleDataException if the provided data cannot
|
||||
* be processed by this formatter. Return the source data if it
|
||||
* is valid. The data may be encapsulated or converted if necessary.
|
||||
*
|
||||
* @param mixed $structuredData Data to validate
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function validate($structuredData);
|
||||
}
|
||||
Reference in New Issue
Block a user