Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
CollectionTrait
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 getParent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCollectionItemListAfterAction
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/*
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23namespace MediaWiki\Extension\Collection\Api;
24
25use ApiBase;
26use MediaWiki\Extension\Collection\Session;
27use MediaWiki\Extension\Collection\Templates\CollectionListTemplate;
28
29trait CollectionTrait {
30    /** @var ApiBase */
31    private $parent;
32
33    /**
34     * Get the parent module.
35     * @return ApiBase
36     */
37    public function getParent() {
38        return $this->parent;
39    }
40
41    /**
42     * @param ApiBase $parent
43     * @param string $moduleName
44     */
45    public function __construct( ApiBase $parent, $moduleName ) {
46        // @phan-suppress-next-line PhanTraitParentReference
47        parent::__construct( $parent->getMain(), $moduleName );
48        $this->parent = $parent;
49    }
50
51    /**
52     * Used to get the list of items from a user's collection after
53     * an article has been added to their collection.
54     */
55    public function getCollectionItemListAfterAction() {
56        $collection = Session::getCollection();
57        $template = new CollectionListTemplate();
58        $template->set( 'collection', $collection );
59
60        $result = [
61            'html' => $template->getHTML(),
62            'collection' => $collection
63        ];
64
65        // @phan-suppress-next-line PhanUndeclaredMethod
66        $this->getResult()->addValue( null, $this->getModuleName(), $result );
67    }
68}