Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
SubversionProxy
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 7
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 canConnect
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFile
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDiff
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getLog
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getDirList
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 _proxy
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace MediaWiki\Extension\CodeReview\Backend;
4
5use Exception;
6use Http;
7
8/**
9 * Using a remote JSON proxy
10 */
11class SubversionProxy extends SubversionAdaptor {
12    public function __construct( $repo, $proxy, $timeout = 30 ) {
13        parent::__construct( $repo );
14        $this->mProxy = $proxy;
15        $this->mTimeout = $timeout;
16    }
17
18    public function canConnect() {
19        // TODO!
20        return true;
21    }
22
23    /**
24     * @param string $path
25     * @param null $rev
26     *
27     * @return never
28     * @throws Exception
29     */
30    public function getFile( $path, $rev = null ) {
31        throw new Exception( 'NYI' );
32    }
33
34    public function getDiff( $path, $rev1, $rev2 ) {
35        return $this->_proxy( [
36            'action' => 'diff',
37            'base' => $this->mRepoPath,
38            'path' => $path,
39            'rev1' => $rev1,
40            'rev2' => $rev2
41        ] );
42    }
43
44    public function getLog( $path, $startRev = null, $endRev = null ) {
45        return $this->_proxy( [
46            'action' => 'log',
47            'base' => $this->mRepoPath,
48            'path' => $path,
49            'start' => $startRev,
50            'end' => $endRev
51        ] );
52    }
53
54    public function getDirList( $path, $rev = null ) {
55        return $this->_proxy( [
56            'action' => 'list',
57            'base' => $this->mRepoPath,
58            'path' => $path,
59            'rev' => $rev
60        ] );
61    }
62
63    protected function _proxy( $params ) {
64        foreach ( $params as $key => $val ) {
65            if ( $val === null ) {
66                // Don't pass nulls to remote
67                unset( $params[$key] );
68            }
69        }
70        $target = $this->mProxy . '?' . wfArrayToCgi( $params );
71        $blob = Http::get( $target, $this->mTimeout );
72        if ( $blob === false ) {
73            throw new Exception( 'SVN proxy error' );
74        }
75        return unserialize( $blob );
76    }
77}