Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
Marketplace_Product_Software
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 7
72
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 get_software_slug
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_download_url
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_plugin_dependencies
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_theme_dependencies
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_managed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_product_slug_or_url
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
1<?php // phpcs:ignore Squiz.Commenting.FileComment.Missing
2/**
3 * Abstract class that contains all the data required to install a product.
4 *
5 * @since 5.2.0
6 * @package WPCOM_Marketplace
7 */
8abstract class Marketplace_Product_Software {
9
10    /**
11     * Product type (plugin, theme, etc).
12     *
13     * @var string
14     */
15    protected string $product_type;
16
17    /**
18     * Product software slug. Used to install the product.
19     *
20     * @var string
21     */
22    protected string $software_slug;
23
24    /**
25     * Download URL of the product. Used to install the product if it's not managed.
26     *
27     * @var string
28     */
29    protected string $download_url;
30
31    /**
32     * List of plugin the product depends on.
33     *
34     * @var array<string>
35     */
36    protected array $plugin_dependencies;
37
38    /**
39     * List of themes the product depends on.
40     *
41     * @var array<string>
42     */
43    protected array $theme_dependencies;
44
45    /**
46     * Whether the product is managed or not.
47     *
48     * @var bool
49     */
50    protected bool $is_managed;
51
52    /**
53     * Marketplace_Product_Software constructor.
54     *
55     * @param string        $software_slug          The product slug used to install the product.
56     * @param bool          $is_managed             Whether the product is managed or not.
57     * @param string        $download_url           The download URL of the product.
58     * @param array<string> $plugin_dependencies    List of plugins the product depends on.
59     * @param array<string> $theme_dependencies     List of themes the product depends on.
60     */
61    public function __construct( string $software_slug, bool $is_managed, string $download_url, array $plugin_dependencies = array(), array $theme_dependencies = array() ) {
62        $this->software_slug       = $software_slug;
63        $this->download_url        = $download_url;
64        $this->plugin_dependencies = $plugin_dependencies;
65        $this->theme_dependencies  = $theme_dependencies;
66        $this->is_managed          = $is_managed;
67    }
68
69    /**
70     * Get the product software slug.
71     *
72     * @return string
73     */
74    public function get_software_slug() {
75        return $this->software_slug;
76    }
77
78    /**
79     * Get the product download URL.
80     *
81     * @return string
82     */
83    public function get_download_url() {
84        return $this->download_url;
85    }
86
87    /**
88     * Get the product plugin dependencies.
89     *
90     * @return array<string>
91     */
92    public function get_plugin_dependencies() {
93        return $this->plugin_dependencies;
94    }
95
96    /**
97     * Get the product theme dependencies.
98     *
99     * @return array<string>
100     */
101    public function get_theme_dependencies() {
102        return $this->theme_dependencies;
103    }
104
105    /**
106     * Check if the product is managed.
107     *
108     * @return bool
109     */
110    public function is_managed() {
111        return $this->is_managed;
112    }
113
114    /**
115     * Get the product slug or URL depending on whether the product is managed.
116     * If the product is managed, the slug is returned. Otherwise, the download URL is returned.
117     *
118     * @return string
119     */
120    public function get_product_slug_or_url() {
121        return $this->is_managed ? $this->software_slug : $this->download_url;
122    }
123}