ModelPostTypeMismatchException   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
1
<?php
2
3
namespace Silk\Post\Exception;
4
5
use WP_Post;
6
7
class ModelPostTypeMismatchException extends \RuntimeException
8
{
9
    const MESSAGE_FORMAT = '{modelClass} instantiated with post of type "{givenPostType}", but requires a post of type "{modelPostType}".';
10
11
    /**
12
     * The model's full class name
13
     * @var string
14
     */
15
    protected $modelClass;
16
17
    /**
18
     * The post object
19
     * @var WP_Post
20
     */
21
    protected $post;
22
23
    /**
24
     * ModelPostTypeMismatchException Constructor.
25
     *
26
     * @param string  $modelClass  The model's full class name
27
     * @param WP_Post $post        The post object
28
     */
29
    public function __construct($modelClass, WP_Post $post)
30
    {
31
        $this->modelClass = $modelClass;
32
        $this->post = $post;
33
        $this->message = str_replace([
34
            '{modelClass}',
35
            '{givenPostType}',
36
            '{modelPostType}'
37
        ], [
38
            $this->modelClass,
39
            $this->post->post_type,
40
            call_user_func([$this->modelClass, 'postTypeId'])
41
        ], static::MESSAGE_FORMAT);
42
    }
43
}
44