Completed
Push — master ( 8b5613...ea1393 )
by Sébastien
04:16
created

JasperCompileManager::compileReport()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 39
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 7.4428

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 39
ccs 19
cts 24
cp 0.7917
rs 6.7272
cc 7
eloc 29
nc 7
nop 1
crap 7.4428
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\Jasper\Proxy\V6;
6
7
use Soluble\Jasper\Exception;
8
use Soluble\Jasper\Proxy\RemoteJavaObjectProxyInterface;
9
use Soluble\Japha\Bridge\Adapter as BridgeAdapter;
10
use Soluble\Japha\Interfaces\JavaObject;
11
use Soluble\Japha\Bridge\Exception\JavaException;
12
13
class JasperCompileManager implements RemoteJavaObjectProxyInterface
14
{
15
    /**
16
     * @var BridgeAdapter
17
     */
18
    protected $ba;
19
20
    /**
21
     * @var \Soluble\Japha\Interfaces\JavaClass
22
     */
23
    protected $compileManager;
24
25 5
    public function __construct(BridgeAdapter $bridgeAdapter)
26
    {
27 5
        $this->ba = $bridgeAdapter;
28 5
        $this->compileManager = $this->ba->javaClass('net.sf.jasperreports.engine.JasperCompileManager');
29 5
    }
30
31
    /**
32
     * Compile the jrxml report file in a blazing fast representation.
33
     *
34
     * @param string $reportFile
35
     *
36
     * @return JavaObject Java('net.sf.jasperreports.engine.JasperReport')
37
     *
38
     * @throws Exception\BrokenXMLReportFileException
39
     * @throws Exception\ReportFileNotFoundException
40
     * @throws JavaException
41
     */
42 5
    public function compileReport(string $reportFile): JavaObject
43
    {
44 5
        $compiledReport = null;
45
46
        try {
47 5
            $compiledReport = $this->compileManager->compileReport($reportFile);
48 2
        } catch (JavaException $e) {
1 ignored issue
show
Bug introduced by
The class Soluble\Japha\Bridge\Exception\JavaException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
49 2
            $className = $e->getJavaClassName();
50
            switch ($className) {
51 2
                case 'net.sf.jasperreports.engine.JRException':
52 2
                    $cause = $e->getCause();
53 2
                    if (strpos($cause, 'java.io.FileNotFoundException') !== false) {
54 1
                        $msg = (file_exists($reportFile)) ?
55
                            'Report file "%s" exists but cannot be located from the java (servlet) side.'
56
                            :
57 1
                            'Report file "%s" cannot be found';
58 1
                        throw new Exception\ReportFileNotFoundException(sprintf(
59 1
                           $msg,
60 1
                           $reportFile
61
                        ));
62 1
                    } elseif (strpos($cause, 'org.xml.sax.SAXParseException') !== false) {
63 1
                        throw new Exception\BrokenXMLReportFileException(sprintf(
64 1
                            'The report file "%s" cannot be parsed. (XML error cause: %s)',
65 1
                            $reportFile,
66 1
                            $cause
67
                        ));
68
                    } else {
69
                        throw $e;
70
                    }
71
                    break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
72
                default:
73
                    throw $e;
74
            }
75
        } catch (\Exception $e) {
76
            throw new Exception\RuntimeException($e->getMessage());
77
        }
78
79 3
        return $compiledReport;
80
    }
81
82
    public function getJavaProxiedObject(): JavaObject
83
    {
84
        return $this->compileManager;
85
    }
86
}
87