DeCaptchaWikiMain::viewHeader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
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
            'en' => 'Description',
18
        ];
19
        $this->texts['readme_main_desc'] = [
20
            'ru' => 'Пакет создан для стандартизации всех сервисов по разгадыванию капч. 
21
            У каждого сервиса есть свои особенности и теперь Вам надо будет всего лишь взглянуть на документацию конкретного сервиса чтобы правильно всё сделать.
22
            Так же пакет покрывает всю функциональсть сервисов. Если же Вам будет чего-то нехватать или будут предложения, я буду только рад их услышать.',
23
            'en' => 'Package created to standardize all services for solving captcha.
24
            Each service has its own features and now You will have to look at the documentation for the specific service to do everything right. 
25
            The package covers the entire functionality services. If You will be something lacking or suggestions, I\'ll be glad to hear them.',
26
        ];
27
        $this->texts['slug_menu_services'] = [
28
            'ru' => 'Сервисы',
29
            'en' => 'Services',
30
        ];
31
        $this->texts['readme_main_services'] = [
32
            'ru' => 'Распознавание капч для всех популярных сервисов',
33
            'en' => 'Recognition captchas for all popular services',
34
        ];
35
        $this->texts['slug_menu_features'] = [
36
            'ru' => 'Особенности',
37
            'en' => 'Features',
38
        ];
39
        $this->texts['readme_main_features'] = [
40
            'ru' => [
41
                '+ Подходит для всех сервисов по распознаванию капч',
42
                '+ Можно легко добавить новый сервис, используя уже готовый движок',
43
                '+ Быстрая и интуительно понятная настройка',
44
                '+ Распознавание как по пути до файла, так и по ссылки',
45
                '+ ReCaptcha v2 без браузера',
46
                '+ Полная документация',
47
                '+ Покрыт тестами',
48
            ],
49
            'en' => [
50
                '+ Suitable for all recognition services captcha',
51
                '+ You can easily add a new service using the existing engine',
52
                '+ Intuitable fast and straightforward setup',
53
                '+ Recognition as the path to the file and links',
54
                '+ ReCaptcha v2 without a browser',
55
                '+ Full documentation',
56
                '+ Covered by tests',
57
            ],
58
        ];
59
    }
60
61
    public function addClass($class)
62
    {
63
        $this->classes[] = $class;
64
    }
65
66
    protected function viewHeader()
67
    {
68
        return 'DeCaptcha
69
================
70
[![Latest Stable Version](https://poser.pugx.org/jumper423/decaptcha/v/stable)](https://packagist.org/packages/jumper423/decaptcha)
71
[![Total Downloads](https://poser.pugx.org/jumper423/decaptcha/downloads)](https://packagist.org/packages/jumper423/decaptcha)
72
[![License](https://poser.pugx.org/jumper423/decaptcha/license)](https://packagist.org/packages/jumper423/decaptcha)
73
74
[![Build Status](https://travis-ci.org/jumper423/decaptcha.svg?branch=master)](https://travis-ci.org/jumper423/decaptcha)
75
[![Dependency Status](https://www.versioneye.com/user/projects/5849f365a662a5004c110a29/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/5849f365a662a5004c110a29)
76
[![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)
77
[![Build Status](https://scrutinizer-ci.com/g/jumper423/decaptcha/badges/build.png?b=master)](https://scrutinizer-ci.com/g/jumper423/decaptcha/build-status/master)
78
[![Code Climate](https://codeclimate.com/github/jumper423/decaptcha/badges/gpa.svg)](https://codeclimate.com/github/jumper423/decaptcha)
79
[![Issue Count](https://codeclimate.com/github/jumper423/decaptcha/badges/issue_count.svg)](https://codeclimate.com/github/jumper423/decaptcha)
80
[![codecov](https://codecov.io/gh/jumper423/decaptcha/branch/master/graph/badge.svg)](https://codecov.io/gh/jumper423/decaptcha)
81
[![HHVM Status](http://hhvm.h4cc.de/badge/jumper423/decaptcha.svg)](http://hhvm.h4cc.de/package/jumper423/decaptcha)
82
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/d485629c-1830-440d-82ab-a567bfa5ddc5/mini.png)](https://insight.sensiolabs.com/projects/d485629c-1830-440d-82ab-a567bfa5ddc5)
83
[![StyleCI](https://styleci.io/repos/75013766/shield?branch=master)](https://styleci.io/repos/75013766)'.PHP_EOL;
84
    }
85
86
    protected function viewMenu($master = '')
87
    {
88
        $str = "+ [{$this->getText(['slug', 'menu', 'another'])}](../{$master}docs/".$this->getFileName($this->lang == 'ru' ? 'en' : 'ru').')'.PHP_EOL;
89
        foreach ([
90
                     ['slug', 'menu', 'desc'],
91
                     ['slug', 'menu', 'features'],
92
                     ['slug', 'menu', 'services'],
93
                     ['install'],
94
                     ['example'],
95
                 ] as $anchor) {
96
            $str .= "+ [{$this->getText($anchor)}](#".implode('-', explode(' ', ($this->lang === 'en' ? mb_strtolower($this->getText($anchor)) : $this->getText($anchor)))).')'.PHP_EOL;
97
        }
98
99
        return $str;
100
    }
101
102
    public function viewServices($master = '')
103
    {
104
        $str = '';
105
        $tt = [];
106
        foreach ($this->classes as $class) {
107
            if (isset($tt[$class->getWiki($this->lang)->getFileName()])) {
108
                continue;
109
            }
110
            $tt[$class->getWiki($this->lang)->getFileName()] = true;
111
            $fromServiceObjectWiki = $class->getWiki($this->lang);
112
            $str .= "+ [{$fromServiceObjectWiki->getText(['service', 'name'])}](../{$master}docs/{$fromServiceObjectWiki->getFileName()})".PHP_EOL;
113
        }
114
115
        return $str;
116
    }
117
118
    public function view($master = '')
119
    {
120
        $str = $this->viewHeader().PHP_EOL;
121
122
        $str .= "{$this->getText(['slug', 'menu'])}".PHP_EOL;
123
        $str .= '--------------'.PHP_EOL;
124
        $str .= $this->viewMenu($master).PHP_EOL.PHP_EOL;
125
126
        $str .= "{$this->getText(['slug', 'menu', 'desc'])}".PHP_EOL;
127
        $str .= '--------------'.PHP_EOL;
128
        $str .= $this->getText(['readme', 'main', 'desc']).PHP_EOL.PHP_EOL;
129
130
        $str .= "{$this->getText(['slug', 'menu', 'features'])}".PHP_EOL;
131
        $str .= '--------------'.PHP_EOL;
132
        $str .= $this->getText(['readme', 'main', 'features'], PHP_EOL).PHP_EOL.PHP_EOL;
133
134
        $str .= "{$this->getText(['slug', 'menu', 'services'])}".PHP_EOL;
135
        $str .= '--------------'.PHP_EOL;
136
        $str .= "{$this->getText(['readme', 'main', 'services'])}".PHP_EOL.PHP_EOL;
137
        $str .= "{$this->viewServices($master)}".PHP_EOL.PHP_EOL;
138
139
        $str .= "{$this->getText(['install'])}".PHP_EOL;
140
        $str .= '--------------'.PHP_EOL;
141
        $str .= "{$this->viewInstall()}".PHP_EOL.PHP_EOL;
142
        $str .= "{$this->getText(['example'])}".PHP_EOL;
143
        $str .= '--------------'.PHP_EOL;
144
        $str .= "{$this->viewExamples()}".PHP_EOL.PHP_EOL;
145
146
        return $str;
147
    }
148
149
    public function getFileName($lang = null)
150
    {
151
        if (is_null($lang)) {
152
            $lang = $this->lang;
153
        }
154
155
        return 'README-'.$lang.'.md';
156
    }
157
158
    public function save()
159
    {
160
        file_put_contents(__DIR__.'/../../docs/'.$this->getFileName(), $this->view());
161
        file_put_contents(__DIR__.'/../../README.md', $this->view('master/'));
162
    }
163
}
164