Service   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 9 2
A hook() 0 25 2
1
<?php
2
3
namespace lloc\Msls\ContentImport;
4
5
use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger;
6
use lloc\Msls\MslsOptions;
7
use lloc\Msls\MslsRegistryInstance;
8
9
/**
10
 * Class Service
11
 *
12
 * A service provider for the content import functionality.
13
 *
14
 * @package lloc\Msls\ContentImport
15
 */
16
class Service extends MslsRegistryInstance {
17
18
	/**
19
	 * Hooks the classes that provide the content import functionality if the content import option is active.
20
	 *
21
	 * @return bool Whether the content import functionality support classes where hooked or not.
22
	 */
23
	public function register() {
24
		if ( ! MslsOptions::instance()->activate_content_import ) {
0 ignored issues
show
Documentation introduced by
The property activate_content_import does not exist on object<lloc\Msls\MslsOptions>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
25
			return false;
26
		}
27
28
		$this->hook();
29
30
		return true;
31
	}
32
33
	/**
34
	 * Hooks the filters and actions for this service provider.
35
	 *
36
	 * Differently from the `register` method this method will not check for options to hook.
37
	 */
38
	public function hook() {
39
		add_action( 'load-post.php', function () {
40
			return ContentImporter::instance()->handle_import();
41
		} );
42
		add_action( 'load-post.php', function () {
43
			add_action( 'admin_notices', function () {
44
				AdminNoticeLogger::instance()->show_last_log();
45
			} );
46
		} );
47
		add_action( 'load-post-new.php', function () {
48
			return ContentImporter::instance()->handle_import();
49
		} );
50
		add_filter( 'wp_insert_post_empty_content', function ( $empty ) {
51
			return ContentImporter::instance()->filter_empty( $empty );
52
		} );
53
		add_filter( 'wp_get_attachment_url', function ( $url, $post_id ) {
54
			return AttachmentPathFinder::instance()->filter_attachment_url( $url, $post_id );
55
		}, 99, 2 );
56
		add_filter( 'wp_calculate_image_srcset', function ( $sources, $sizeArray, $imageSrc, $imageMeta, $attachmentId ) {
57
			return AttachmentPathFinder::instance()->filter_srcset( $sources, $sizeArray, $imageSrc, $imageMeta, $attachmentId );
58
		}, 99, 5 );
59
60
		if ( is_admin() ) {
61
		}
62
	}
63
}