Completed
Push — master ( a15ea7...cf9bf8 )
by Владислав
02:13
created

DeCaptchaWikiMain::view()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
3
namespace jumper423\decaptcha\core;
4
5
/**
6
 * Class DeCaptchaWikiMain.
7
 */
8
class DeCaptchaWikiMain extends DeCaptchaWiki
9
{
10
    protected $classes = [];
11
12
    public function __construct($class)
13
    {
14
        parent::__construct($class);
15
        $this->texts['slug_menu_desc'] = [
16
            'ru' => 'Описание',
17
        ];
18
        $this->texts['readme_main_desc'] = [
19
            'ru' => 'Пакет создан для стандартизации всех сервисов по расгадыванию капч. 
20
            У каждого сервиса есть свои особенности и теперь Вам надо будет всего лишь взглянуть на документацию конкретного сервиса чтобы правильно всё сделать.
21
            Так же пакет покрывает всю функциональсть сервисов. Если же Вам будет чего-то нехватать или будут предложения, я буду только рад их услышать.',
22
        ];
23
        $this->texts['slug_menu_services'] = [
24
            'ru' => 'Сервисы',
25
        ];
26
        $this->texts['readme_main_services'] = [
27
            'ru' => 'Распознавание капч для всех популярных сервисов',
28
        ];
29
        $this->texts['slug_menu_features'] = [
30
            'ru' => 'Особенности',
31
        ];
32
        $this->texts['readme_main_features'] = [
33
            'ru' => [
34
                '+ Подходит для всех сервисов по распознаванию капч',
35
                '+ Можно легко добавить новый сервис, используя уже готовый движок',
36
                '+ Быстрая и интуительно понятная настройка',
37
                '+ Распозвание как по пути до файла, так и по ссылки',
38
                '+ ReCaptcha v2 без браузера',
39
                '+ Полная документация',
40
                '+ Покрыт тестами',
41
            ],
42
        ];
43
    }
44
45
    public function addClass($class)
46
    {
47
        $this->classes[] = $class;
48
    }
49
50
    protected function viewHeader()
51
    {
52
        return 'DeCaptcha
53
================
54
[![Latest Stable Version](https://poser.pugx.org/jumper423/decaptcha/v/stable)](https://packagist.org/packages/jumper423/decaptcha)
55
[![Total Downloads](https://poser.pugx.org/jumper423/decaptcha/downloads)](https://packagist.org/packages/jumper423/decaptcha)
56
[![License](https://poser.pugx.org/jumper423/decaptcha/license)](https://packagist.org/packages/jumper423/decaptcha)
57
58
[![Build Status](https://travis-ci.org/jumper423/decaptcha.svg?branch=master)](https://travis-ci.org/jumper423/decaptcha)
59
[![Dependency Status](https://www.versioneye.com/user/projects/5849f365a662a5004c110a29/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/5849f365a662a5004c110a29)
60
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jumper423/decaptcha/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jumper423/decaptcha/?branch=master)
61
[![Build Status](https://scrutinizer-ci.com/g/jumper423/decaptcha/badges/build.png?b=master)](https://scrutinizer-ci.com/g/jumper423/decaptcha/build-status/master)
62
[![Code Climate](https://codeclimate.com/github/jumper423/decaptcha/badges/gpa.svg)](https://codeclimate.com/github/jumper423/decaptcha)
63
[![Issue Count](https://codeclimate.com/github/jumper423/decaptcha/badges/issue_count.svg)](https://codeclimate.com/github/jumper423/decaptcha)
64
[![codecov](https://codecov.io/gh/jumper423/decaptcha/branch/master/graph/badge.svg)](https://codecov.io/gh/jumper423/decaptcha)
65
[![HHVM Status](http://hhvm.h4cc.de/badge/jumper423/decaptcha.svg)](http://hhvm.h4cc.de/package/jumper423/decaptcha)
66
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/d485629c-1830-440d-82ab-a567bfa5ddc5/mini.png)](https://insight.sensiolabs.com/projects/d485629c-1830-440d-82ab-a567bfa5ddc5)
67
[![StyleCI](https://styleci.io/repos/75013766/shield?branch=master)](https://styleci.io/repos/75013766)' . PHP_EOL;
68
    }
69
70
    /**
71
     * @param string|array $name
72
     * @param string|array $value
73
     */
74 View Code Duplication
    public function setText($name, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        if (is_array($name)) {
77
            $name = implode('_', $name);
78
        }
79
        $this->texts[$name] = $value;
80
    }
81
82
    /**
83
     * @param string|array $name
84
     * @param string $separator
85
     *
86
     * @return string|array
87
     */
88 View Code Duplication
    public function getText($name, $separator = '; ')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        $getResult = function ($name, $texts) {
91
            if (is_array($name)) {
92
                $name = implode('_', $name);
93
            }
94
            if (!isset($texts[$name])) {
95
                return null;
96
            }
97
            if (is_array($texts[$name])) {
98
                if (isset($texts[$name][$this->lang])) {
99
                    return $texts[$name][$this->lang];
100
                }
101
102
                return array_values($texts[$name])[0];
103
            }
104
105
            return $texts[$name];
106
        };
107
        $result = $getResult($name, $this->texts);
108
        if (is_array($result)) {
109
            if ($separator) {
110
                $result = implode($separator, $result);
111
            }
112
        }
113
114
        return $result;
115
    }
116
117
118
    protected function viewMenu()
119
    {
120
        $str = "+ [{$this->getText(['slug', 'menu', 'another'])}](../docs/" . $this->getFileName($this->lang == 'ru' ? 'en' : 'ru') . ')' . PHP_EOL;
121
        foreach ([
122
                     ['slug', 'menu', 'desc'],
123
                     ['slug', 'menu', 'features'],
124
                     ['slug', 'menu', 'services'],
125
                     ['install'],
126
                     ['example'],
127
                 ] as $anchor) {
128
            $str .= "+ [{$this->getText($anchor)}](#" . implode('-', explode(' ', $this->getText($anchor))) . ')' . PHP_EOL;
129
        }
130
131
        return $str;
132
    }
133
134
    public function viewServices()
135
    {
136
        $str = '';
137
        $tt = [];
138
        foreach ($this->classes as $class) {
139
            if (isset($tt[$class->getWiki($this->lang)->getFileName()])) {
140
                continue;
141
            }
142
            $tt[$class->getWiki($this->lang)->getFileName()] = true;
143
            $fromServiceObjectWiki = $class->getWiki($this->lang);
144
            $str .= "+ [{$fromServiceObjectWiki->getText(['service', 'name'])}](../docs/{$fromServiceObjectWiki->getFileName()})" . PHP_EOL;
145
        }
146
        return $str;
147
    }
148
149
    public function view()
150
    {
151
        $str = $this->viewHeader() . PHP_EOL;
152
153
        $str .= "###{$this->getText(['slug', 'menu'])}" . PHP_EOL;
154
        $str .= $this->viewMenu() . PHP_EOL . PHP_EOL;
155
156
        $str .= "###{$this->getText(['slug','menu','desc'])}" . PHP_EOL;
157
        $str .= $this->getText(['readme', 'main', 'desc']) . PHP_EOL . PHP_EOL;
158
159
        $str .= "###{$this->getText(['slug','menu','features'])}" . PHP_EOL;
160
        $str .= $this->getText(['readme', 'main', 'features'], PHP_EOL) . PHP_EOL . PHP_EOL;
161
162
        $str .= "###{$this->getText(['slug','menu','services'])}" . PHP_EOL;
163
        $str .= "{$this->getText(['readme','main','services'])}" . PHP_EOL . PHP_EOL;
164
        $str .= "{$this->viewServices()}" . PHP_EOL . PHP_EOL;
165
166
167
        $str .= "###{$this->getText(['install'])}" . PHP_EOL;
168
        $str .= "{$this->viewInstall()}" . PHP_EOL . PHP_EOL;
169
        $str .= "###{$this->getText(['example'])}" . PHP_EOL;
170
        $str .= "{$this->viewExamples()}" . PHP_EOL . PHP_EOL;
171
172
        return $str;
173
    }
174
175
    public function getFileName($lang = null)
176
    {
177
        if (is_null($lang)) {
178
            $lang = $this->lang;
179
        }
180
        return 'README-' . $lang . '.md';
181
    }
182
183
    public function save()
184
    {
185
        file_put_contents(__DIR__ . '/../../docs/' . $this->getFileName(), $this->view());
186
        file_put_contents(__DIR__ . '/../../README.md', $this->view());
187
    }
188
}
189