Site   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 40
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A idSitePrefix() 0 3 1
A id() 0 3 1
A isMediaSite() 0 3 1
1
<?php # -*- coding: utf-8 -*-
2
declare(strict_types=1);
3
4
namespace MultisiteGlobalMedia;
5
6
/**
7
 * Class Site
8
 */
9
class Site
10
{
11
    const SITE_ID = 'global_media.site_id';
12
    const META_KEY_SITE_ID = 'global_media_site_id';
13
14
    const SITE_ID_PREFIX_RIGHT_PAD = '00000';
15
16
    /**
17
     * Return the ID of site that store the media files.
18
     *
19
     * @since  2017-12-01
20
     * @return integer The site ID.
21
     */
22
    public function id(): int
23
    {
24
        return (int)apply_filters(self::SITE_ID, 1);
25
    }
26
27
    /**
28
     * Return the site id prefix for attachments
29
     *
30
     * @return string
31
     */
32
    public function idSitePrefix(): string
33
    {
34
        return $this->id() . self::SITE_ID_PREFIX_RIGHT_PAD;
35
    }
36
37
    /**
38
     * Returns whether or not we're currently on the network media library site,
39
     * regardless of any switching that's occurred.
40
     *
41
     * `$current_blog` can be used to determine the "actual" site as it doesn't
42
     * change when switching sites.
43
     *
44
     * @return bool Whether we're on the network media library site.
45
     */
46
    public function isMediaSite(): bool
47
    {
48
        return ($this->id() === (int)$GLOBALS['current_blog']->blog_id);
49
    }
50
}
51