| Conditions | 4 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 4.0058 |
| Changes | 0 | ||
| 1 | <?php |
||
| 51 | 1 | public function parse(): self |
|
| 52 | { |
||
| 53 | 1 | if ($this->file->isFile()) { |
|
| 54 | 1 | if (!$this->file->isReadable()) { |
|
| 55 | throw new \RuntimeException('Cannot read file'); |
||
| 56 | } |
||
| 57 | 1 | preg_match( |
|
| 58 | 1 | '/'.self::PATTERN.'/s', |
|
| 59 | 1 | $this->file->getContents(), |
|
| 60 | 1 | $matches |
|
| 61 | ); |
||
| 62 | // if there is not front matter, set body only |
||
| 63 | 1 | if (empty($matches)) { |
|
| 64 | 1 | $this->body = $this->file->getContents(); |
|
| 65 | |||
| 66 | 1 | return $this; |
|
| 67 | } |
||
| 68 | 1 | $this->frontmatter = trim($matches[1]); |
|
| 69 | 1 | $this->body = trim($matches[2]); |
|
| 70 | } |
||
| 71 | |||
| 72 | 1 | return $this; |
|
| 73 | } |
||
| 95 |