Passed
Push — master ( a5e8db...945884 )
by Danny
02:33
created

Rewrite::rewriteSetStructure()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
namespace PressCLI\WPCLI;
3
4
use PressCLI\WPCLI\CLI;
5
use PressCLI\Option\Configuration;
6
7
trait Rewrite
8
{
9
    /**
10
     * Flushes the rewrite rules.
11
     */
12
    public static function rewriteFlush()
13
    {
14
        CLI::execCommand('rewrite', ['flush']);
15
    }
16
17
    /**
18
     * Sets the default permalink rewrite structure.
19
     */
20
    public static function rewriteSetStructure()
21
    {
22
        $config = Configuration::get();
23
        $rewrite = isset($config['rewrite']) ? $config['rewrite'] : [];
24
        $rewrite = isset($rewrite['structure']) ? $rewrite['structure'] : '/%postname%/';
25
26
        CLI::execCommand('rewrite', ['structure', "'{$rewrite}'"], ['hard' => '']);
27
        CLI::execCommand('rewrite', ['flush'], ['hard' => '']);
28
    }
29
}
30