Initial commit
This commit is contained in:
47
src/Analyzer/Base/AnalyzableInterface.php
Normal file
47
src/Analyzer/Base/AnalyzableInterface.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 magdev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author magdev
|
||||
* @copyright 2018 Marco Grätsch
|
||||
* @package magdev/dossier
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
|
||||
namespace Magdev\Dossier\Analyzer\Base;
|
||||
|
||||
/**
|
||||
* Interface for analyzable models
|
||||
*
|
||||
* @author magdev
|
||||
*/
|
||||
interface AnalyzableInterface
|
||||
{
|
||||
/**
|
||||
* Get the data to analyze
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAnalyzerData(): array;
|
||||
}
|
||||
|
||||
39
src/Analyzer/Base/AnalyzerException.php
Normal file
39
src/Analyzer/Base/AnalyzerException.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 magdev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author magdev
|
||||
* @copyright 2018 Marco Grätsch
|
||||
* @package magdev/dossier
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
|
||||
namespace Magdev\Dossier\Analyzer\Base;
|
||||
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
|
||||
class AnalyzerException extends RuntimeException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
55
src/Analyzer/Base/AnalyzerInterface.php
Normal file
55
src/Analyzer/Base/AnalyzerInterface.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 magdev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author magdev
|
||||
* @copyright 2018 Marco Grätsch
|
||||
* @package magdev/dossier
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
|
||||
namespace Magdev\Dossier\Analyzer\Base;
|
||||
|
||||
/**
|
||||
* Interface for analyzers
|
||||
*
|
||||
* @author magdev
|
||||
*/
|
||||
interface AnalyzerInterface
|
||||
{
|
||||
/**
|
||||
* Get the name of the analyzer
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string;
|
||||
|
||||
/**
|
||||
* Analyze a model
|
||||
*
|
||||
* @param \Magdev\Dossier\Analyzer\Base\AnalyzableInterface $model
|
||||
* @return mixed
|
||||
*/
|
||||
public function analyze(AnalyzableInterface $model);
|
||||
}
|
||||
|
||||
72
src/Analyzer/ModelStatusAnalyzer.php
Normal file
72
src/Analyzer/ModelStatusAnalyzer.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 magdev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author magdev
|
||||
* @copyright 2018 Marco Grätsch
|
||||
* @package magdev/dossier
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
|
||||
namespace Magdev\Dossier\Analyzer;
|
||||
|
||||
use Magdev\Dossier\Analyzer\Base\AnalyzerInterface;
|
||||
use Magdev\Dossier\Analyzer\Base\AnalyzableInterface;
|
||||
|
||||
/**
|
||||
* Dossier status analyzer
|
||||
*
|
||||
* @author magdev
|
||||
*/
|
||||
class ModelStatusAnalyzer implements AnalyzerInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see \Magdev\Dossier\Analyzer\Base\AnalyzerInterface::getName()
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'model.status';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see \Magdev\Dossier\Analyzer\Base\AnalyzerInterface::analyze()
|
||||
* @return int
|
||||
*/
|
||||
public function analyze(AnalyzableInterface $model)
|
||||
{
|
||||
$data = $model->getAnalyzerData();
|
||||
$base = sizeof($data);
|
||||
$counter = 0;
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value) {
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
return ceil(($counter * 100) / $base);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user