Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
5 / 5
Sha256Strategy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
5 / 5
 supports(AlgorithmInterface $algorithm)
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 encode($data)
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
<?php
/**
 * @author Krzysztof Gzocha <krzysztof.gzocha@xsolve.pl>
 */
namespace Team3\PayU\SignatureCalculator\Encoder\Strategy;
use Team3\PayU\SignatureCalculator\Encoder\Algorithms\AlgorithmInterface;
use Team3\PayU\SignatureCalculator\Encoder\Algorithms\Sha256Algorithm;
use Team3\PayU\SignatureCalculator\Encoder\EncoderException;
class Sha256Strategy implements EncoderStrategyInterface
{
    /**
     * @param AlgorithmInterface $algorithm
     *
     * @return bool
     */
    public function supports(AlgorithmInterface $algorithm)
    {
        return $algorithm instanceof Sha256Algorithm;
    }
    /**
     * @param string $data
     *
     * @return string
     * @throws EncoderException
     */
    public function encode($data)
    {
        if (!function_exists('hash')) {
            throw new EncoderException(
                'There is no hash function defined. Could not encode data.'
            );
        }
        return hash('sha256', $data);
    }
}