Completed
Push — master ( ca910a...8ffcad )
by Evan
02:52
created

ModelPostTypeMismatchException   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
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
    protected $modelClass;
13
    protected $post;
14
15
    public function __construct($modelClass, WP_Post $post)
16
    {
17
        $this->modelClass = $modelClass;
18
        $this->post = $post;
19
        $this->message = str_replace([
20
            '{modelClass}',
21
            '{givenPostType}',
22
            '{modelPostType}'
23
        ], [
24
            $this->modelClass,
25
            $this->post->post_type,
26
            constant($this->modelClass . '::POST_TYPE')
27
        ], static::MESSAGE_FORMAT);
28
    }
29
}
30