Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Status
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 3
110
0.00% covered (danger)
0.00%
0 / 1
 get
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
20
 set
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
30
 reset
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2namespace NewfoldLabs\WP\Module\Onboarding\Compatibility;
3
4use NewfoldLabs\WP\Module\Onboarding\Data\Options;
5
6/**
7 * Class Status
8 */
9class Status {
10
11    /**
12     * Default Scan Status
13     *
14     * @var string
15     */
16    public static $default = 'unscanned';
17
18    /**
19     * Get Scan Status
20     *
21     * @param null|string $type Set to 'all' to return the data array
22     */
23    public static function get( $type = null ) {
24        $data = \get_option( Options::get_option_name( 'compatibility_results' ), self::$default );
25        if ( 'all' === $type ) {
26            return $data;
27        }
28        if ( is_array( $data ) && ! empty( $data['status'] ) ) {
29            return $data['status'];
30        }
31
32        return self::$default;
33    }
34
35    /**
36     * Set Scan Status
37     *
38     * @param object $status - Scan object to set
39     */
40    public static function set( $status ) {
41        $data = array();
42        if ( ! empty( $status ) && is_string( $status ) ) {
43            $data['status']    = $status;
44            $data['timestamp'] = current_time( 'mysql' );
45
46            return \update_option( Options::get_option_name( 'compatibility_results' ), $data );
47        } elseif ( ! empty( $status && is_object( $status ) ) ) {
48            $data['status']    = $status->result;
49            $data['timestamp'] = \current_time( 'mysql' );
50        }
51
52        \update_option( Options::get_option_name( 'compatibility_results' ), $data );
53
54        return false;
55    }
56
57    /**
58     * Reset/Delete the stored scan results
59     */
60    public static function reset() {
61        \delete_option( Options::get_option_name( 'compatibility_results' ) );
62    }
63}