Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
6 / 8
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
TipsAssembler
75.00% covered (warning)
75.00%
6 / 8
66.67% covered (warning)
66.67%
2 / 3
3.14
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 setMessageLocalizer
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTips
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace GrowthExperiments\HelpPanel\Tips;
4
5use GrowthExperiments\NewcomerTasks\ConfigurationLoader\ConfigurationLoader;
6use GrowthExperiments\NewcomerTasks\TaskType\TaskType;
7use MediaWiki\Context\IContextSource;
8use MessageLocalizer;
9
10/**
11 * Assemble tips in HTML for display in suggested edits panel.
12 */
13class TipsAssembler {
14
15    /**
16     * @var IContextSource
17     */
18    private $messageLocalizer;
19    /**
20     * @var ConfigurationLoader
21     */
22    private $configurationLoader;
23
24    /**
25     * @var TipNodeRenderer
26     */
27    private $tipNodeRenderer;
28
29    /**
30     * @param ConfigurationLoader $configurationLoader
31     * @param TipNodeRenderer $tipNodeRenderer
32     */
33    public function __construct(
34        ConfigurationLoader $configurationLoader, TipNodeRenderer $tipNodeRenderer
35    ) {
36        $this->configurationLoader = $configurationLoader;
37        $this->tipNodeRenderer = $tipNodeRenderer;
38    }
39
40    /**
41     * @param MessageLocalizer $messageLocalizer
42     */
43    public function setMessageLocalizer(
44        MessageLocalizer $messageLocalizer
45    ): void {
46        $this->messageLocalizer = $messageLocalizer;
47        $this->tipNodeRenderer->setMessageLocalizer( $messageLocalizer );
48    }
49
50    /**
51     * Get an array of rendered HTML.
52     *
53     * Each index in the array corresponds to a tab in the suggested edits
54     * guidance screen in the help panel.
55     *
56     * Obtain a TipLoader, load the tips, and pass each tip node through the
57     * renderer.
58     *
59     * @param string $skinName
60     * @param string $editor
61     * @param TaskType[] $taskTypes
62     * @param string $taskTypeId
63     * @param string $dir
64     * @return array
65     */
66    public function getTips(
67        string $skinName, string $editor, array $taskTypes, string $taskTypeId, string $dir
68    ): array {
69        $tipLoader = new TipLoader( $this->configurationLoader, $this->messageLocalizer );
70        return array_values( array_map( function ( $tipNodes ) use ( $skinName, $dir ) {
71            return $this->tipNodeRenderer->render( $tipNodes, $skinName, $dir );
72        }, $tipLoader->loadTipNodes( $skinName, $editor, $taskTypes, $taskTypeId ) ) );
73    }
74
75}