Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 34
Survey
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 6
110
0.00% covered (danger)
0.00%
0 / 34
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 11
 getResourceLoaderModuleName
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getAudience
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getMessages
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 10
 toArray
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 10
 isEnabled
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
<?php
namespace QuickSurveys;
abstract class Survey {
    /**
     * @var string The friendly name of the survey
     */
    private $name;
    /**
     * @var string The question that the survey is posing to the user
     */
    private $question;
    /**
     * @var string|null
     */
    private $additionalInfo;
    /**
     * @var string|null
     */
    private $confirmMsg;
    /**
     * @var SurveyAudience describes the audience who can participate in a survey
     */
    private $audience;
    /**
     * @var string|null A user-friendly description of, or introduction to, the question
     */
    private $description;
    /**
     * @var bool Whether the survey is enabled
     */
    private $isEnabled;
    /**
     * @var float The percentage of users that will see the survey expressed as a fraction
     */
    private $coverage;
    /**
     * A platform can operate in one or more modes: mobile operates in 'stable' or 'beta' mode;
     * and desktop only operates in 'stable' mode.
     *
     * The platforms that the survey can be displayed on, therefore, are represented as a map of
     * platform to a set of platform modes, i.e.
     *
     * <code><pre>
     * <?php
     * $platform = array(
     *   'desktop' => array(
     *       'stable',
     *   ),
     *   'mobile' => array(
     *       'stable',
     *       'beta',
     *   ),
     * );
     * </pre></code>
     *
     * @var array[] The platforms that the survey can be displayed on
     */
    private $platforms;
    /**
     * @var string|null The description of the privacy policy of the website that hosts the survey.
     */
    private $privacyPolicy;
    public function __construct(
        $name,
        $question,
        $description,
        $isEnabled,
        $coverage,
        array $platforms,
        $privacyPolicy,
        $additionalInfo,
        $confirmMsg,
        SurveyAudience $audience
    ) {
        $this->name = $name;
        $this->question = $question;
        $this->description = $description;
        $this->isEnabled = $isEnabled;
        $this->coverage = $coverage;
        $this->platforms = $platforms;
        $this->privacyPolicy = $privacyPolicy;
        $this->additionalInfo = $additionalInfo;
        $this->confirmMsg = $confirmMsg;
        $this->audience = $audience;
    }
    /**
     * Returns the name of the ResourceLoader module
     *
     * @return string
     */
    public function getResourceLoaderModuleName(): string {
        return 'ext.quicksurveys.survey.' . str_replace( ' ', '.', $this->name );
    }
    public function getAudience(): SurveyAudience {
        return $this->audience;
    }
    /**
     * Gets the list of i18n message keys that the survey uses
     *
     * @return string[]
     */
    public function getMessages(): array {
        $messages = [
            $this->question,
        ];
        if ( !empty( $this->description ) ) {
            $messages[] = $this->description;
        }
        if ( !empty( $this->privacyPolicy ) ) {
            $messages[] = $this->privacyPolicy;
        }
        if ( !empty( $this->additionalInfo ) ) {
            $messages[] = $this->additionalInfo;
        }
        if ( !empty( $this->confirmMsg ) ) {
            $messages[] = $this->confirmMsg;
        }
        return $messages;
    }
    /**
     * Returns the JSON-encodable, minimal representation of the survey
     *
     * @return array
     */
    public function toArray(): array {
        return [
            'audience' => $this->audience->toArray(),
            'name' => $this->name,
            'question' => $this->question,
            'description' => $this->description,
            'module' => $this->getResourceLoaderModuleName(),
            'coverage' => $this->coverage,
            'platforms' => $this->platforms,
            'privacyPolicy' => $this->privacyPolicy,
            'additionalInfo' => $this->additionalInfo,
            'confirmMsg' => $this->confirmMsg,
        ];
    }
    /**
     * Gets whether the survey is enabled
     *
     * @return bool
     */
    public function isEnabled(): bool {
        return $this->isEnabled;
    }
}