Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractParser
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
3 / 3
16
100.00% covered (success)
100.00%
1 / 1
 getFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getData
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStreamType
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
14
 parse
n/a
0 / 0
n/a
0 / 0
0
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Pdf\Build;
15
16use Pop\Pdf\Document\AbstractDocument;
17
18/**
19 * Abstract Pdf parser class
20 *
21 * @category   Pop
22 * @package    Pop\Pdf
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    5.0.0
27 */
28abstract class AbstractParser implements ParserInterface
29{
30
31    /**
32     * Imported PDF file
33     * @var ?string
34     */
35    protected ?string $file = null;
36
37    /**
38     * Imported PDF data stream
39     * @var ?string
40     */
41    protected ?string $data = null;
42
43    /**
44     * Get the file
45     *
46     * @return string
47     */
48    public function getFile(): string
49    {
50        return $this->file;
51    }
52
53    /**
54     * Get the data stream
55     *
56     * @return string
57     */
58    public function getData(): string
59    {
60        return $this->data;
61    }
62
63    /**
64     * Get the object stream type
65     *
66     * @param  string $stream
67     * @return string
68     */
69    protected function getStreamType(string $stream): string
70    {
71        if ((str_contains($stream, '/Catalog')) && (str_contains($stream, '/Pages'))) {
72            $type = 'root';
73        } else if ((str_contains($stream, '/Count')) && (str_contains($stream, '/Kids'))) {
74            $type = 'parent';
75        } else if ((str_contains($stream, '/Parent')) && (str_contains($stream, '/MediaBox'))) {
76            $type = 'page';
77        } else if ((str_contains($stream, '/Creator')) || (str_contains($stream, '/CreationDate')) ||
78            (str_contains($stream, '/ModDate')) || (str_contains($stream, '/Author')) ||
79            (str_contains($stream, '/Title')) || (str_contains($stream, '/Subject')) ||
80            (str_contains($stream, '/Producer'))) {
81            $type = 'info';
82        } else {
83            $type = 'stream';
84        }
85
86        return $type;
87    }
88
89    /**
90     * Parse the PDF data
91     *
92     * @param  mixed  $pages
93     * @return AbstractDocument
94     */
95    abstract public function parse(mixed $pages = null): AbstractDocument;
96
97}