Completed
Branch develop (2a5993)
by Evan
02:52
created

ModelPostTypeMismatchException   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 37
rs 10
wmc 1
lcom 0
cbo 0

1 Method

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