Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
71.43% covered (warning)
71.43%
5 / 7
CRAP
81.25% covered (warning)
81.25%
13 / 16
SearchProfileRepositoryTransformer
0.00% covered (danger)
0.00%
0 / 1
71.43% covered (warning)
71.43%
5 / 7
11.80
81.25% covered (warning)
81.25%
13 / 16
 __construct
0.00% covered (danger)
0.00%
0 / 1
4.25
75.00% covered (warning)
75.00%
6 / 8
 repositoryType
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 repositoryName
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getProfile
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 hasProfile
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 listExposedProfiles
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 transform
0.00% covered (danger)
0.00%
0 / 1
2.15
66.67% covered (warning)
66.67%
2 / 3
<?php
namespace CirrusSearch\Profile;
/**
 * Transforms profile content based on a transformer implementation.
 */
class SearchProfileRepositoryTransformer implements SearchProfileRepository {
    /**
     * @var SearchProfileRepository
     */
    private $repository;
    /**
     * @var ArrayPathSetter
     */
    private $transformer;
    /**
     * @param SearchProfileRepository $repository
     * @param array|ArrayPathSetter $transformer
     */
    public function __construct( SearchProfileRepository $repository, $transformer ) {
        if ( is_array( $transformer ) ) {
            $transformer = new ArrayPathSetter( $transformer );
        } elseif ( !$transformer instanceof ArrayPathSetter ) {
            throw new \InvalidArgumentException( '$transformer must be array|ArrayPathSetter, got ' .
                ( is_object( $transformer ) ? get_class( $transformer ) : gettype( $transformer ) ) );
        }
        $this->repository = $repository;
        $this->transformer = $transformer;
    }
    /**
     * The repository type
     * @return string
     */
    public function repositoryType() {
        return $this->repository->repositoryType();
    }
    /**
     * The repository name
     * @return string
     */
    public function repositoryName() {
        return $this->repository->repositoryName();
    }
    /**
     * Load a profile named $name
     * @param string $name
     * @return array|null the profile data or null if not found
     */
    public function getProfile( $name ) {
        return $this->transform( $this->repository->getProfile( $name ) );
    }
    /**
     * Check if a profile named $name exists in this repository
     * @param string $name
     * @return bool
     */
    public function hasProfile( $name ) {
        return $this->repository->hasProfile( $name );
    }
    /**
     * Get the list of profiles that we want to expose to the user.
     *
     * @return array[] list of profiles indexed by name
     */
    public function listExposedProfiles() {
        return array_map( [ $this, 'transform' ], $this->repository->listExposedProfiles() );
    }
    /**
     * Transform the profile
     * @param array|null $profile
     * @return array|null
     */
    private function transform( array $profile = null ) {
        if ( $profile === null ) {
            return null;
        }
        return $this->transformer->transform( $profile );
    }
}