Commit af6f4df3 authored by LONGMAN's avatar LONGMAN

Fixed coding standart issues, improved readme

parent 999ee2e7
...@@ -30,5 +30,5 @@ before_script: ...@@ -30,5 +30,5 @@ before_script:
- mysql -e 'create database telegrambot; use telegrambot; source structure.sql;' - mysql -e 'create database telegrambot; use telegrambot; source structure.sql;'
script: script:
- vendor/bin/phpunit - ./vendor/bin/phpunit
- vendor/bin/phpcs --report=full --extensions=php -np --standard=build/phpcs . - ./vendor/bin/phpcs --standard=phpcs.xml -snp --encoding=utf-8 src/ --report-width=150
...@@ -5,11 +5,11 @@ Before you contribute code to php-telegram-bot, please make sure it conforms to ...@@ -5,11 +5,11 @@ Before you contribute code to php-telegram-bot, please make sure it conforms to
cd php-telegram-bot cd php-telegram-bot
composer update composer update
vendor/bin/phpcs --report=full --extensions=php -np --standard=build/phpcs . ./vendor/bin/phpcs --standard=phpcs.xml -sp --encoding=utf-8 src/ --report-width=150
Which should give you no output, indicating that there are no coding standard errors. And then: Which should give you no output, indicating that there are no coding standard errors. And then:
vendor/bin/phpunit ./vendor/bin/phpunit
Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools. Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools.
...@@ -52,11 +52,3 @@ Example for a function or methods: ...@@ -52,11 +52,3 @@ Example for a function or methods:
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
``` ```
- No empty line after class declaration
- No empty line after `<?php`
- Last element of a multi-line array must be followed by a comma
- One empty line after the docblock header
- Array elements and `use` statements should be written in a logical order, preferrably alphabetically
- Use [] instead of array()
- Use single quotes (`'`) for string
- Leave space in front and behind the concatenation operator `.`
...@@ -11,6 +11,49 @@ ...@@ -11,6 +11,49 @@
A Telegram Bot based on the official [Telegram Bot API](https://core.telegram.org/bots/api) A Telegram Bot based on the official [Telegram Bot API](https://core.telegram.org/bots/api)
## Table of Contents
- [Introduction](#introduction)
- [Instructions](#instructions)
- [Create your first bot](#create-your-first-bot)
- [Require this package with Composer](#require-this-package-with-composer)
- [Choose how to retrieve Telegram updates](#choose-how-to-retrieve-telegram-updates)
- [Webhook installation](#webhook-installation)
- [Self Signed Certificate](#self-signed-certificate)
- [Unset Webhook](#unset-webhook)
- [getUpdate installation](#getupdate-installation)
- [Support](#support)
- [Types](#types)
- [Inline Query](#inline-query)
- [Methods](#methods)
- [Send Message](#send-message)
- [Send Photo](#send-photo)
- [Send Chat Action](#send-chat-action)
- [getUserProfilePhoto](#getuserprofilephoto)
- [getFile and dowloadFile](#getfile-and-dowloadfile)
- [Send message to all active chats](#send-message-to-all-active-chats)
- [Utils](#utils)
- [MySQL storage (Recommended)](#mysql-storage-recommended)
- [Channels Support](#channels-support)
- [Commands](#commands)
- [Predefined Commands](#predefined-commands)
- [Custom Commands](#custom-commands)
- [Commands Configuration](#commands-configuration)
- [Admin Commands](#admin-commands)
- [Set Admins](#set-admins)
- [Channel Administration](#channel-administration)
- [Upload and Download directory path](#upload-and-download-directory-path)
- [Logging](#logging)
- [Documentation](#documentation)
- [Projects with this library](#projects-with-this-library)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
- [License](#license)
- [Credits](#credits)
## Introduction ## Introduction
...@@ -199,7 +242,7 @@ $result = $telegram->setWebHook($hook_url, $certificate_path); ...@@ -199,7 +242,7 @@ $result = $telegram->setWebHook($hook_url, $certificate_path);
Edit *example/unset.php* with your bot credentials and execute it. Edit *example/unset.php* with your bot credentials and execute it.
## getUpdate installation ### getUpdate installation
The MySQL database must be active! The MySQL database must be active!
...@@ -353,6 +396,8 @@ With [admin commands](#admin-commands) you can manage your channels directly wit ...@@ -353,6 +396,8 @@ With [admin commands](#admin-commands) you can manage your channels directly wit
### Commands ### Commands
#### Predefined Commands
The bot is able to recognise commands in a chat with multiple bots (/command@mybot). The bot is able to recognise commands in a chat with multiple bots (/command@mybot).
It can execute command triggering a chat event. Here's the list: It can execute command triggering a chat event. Here's the list:
...@@ -375,6 +420,8 @@ Favourite number? **/1, /134** ...@@ -375,6 +420,8 @@ Favourite number? **/1, /134**
**GenericmessageCommand.php** lets you handle any type of message. **GenericmessageCommand.php** lets you handle any type of message.
#### Custom Commands
Maybe you would like to develop your own commands. A good practice is Maybe you would like to develop your own commands. A good practice is
to store them outside *vendor/*. This can be done using: to store them outside *vendor/*. This can be done using:
...@@ -399,6 +446,9 @@ Enabling this feature, the admin bot can perform some super user commands like: ...@@ -399,6 +446,9 @@ Enabling this feature, the admin bot can perform some super user commands like:
- Send message to all chats */sendtoall* - Send message to all chats */sendtoall*
- List all the chats started with the bot */chats* - List all the chats started with the bot */chats*
- Post any content to your channels */sendtochannel* (NEW! see below how to configure it) - Post any content to your channels */sendtochannel* (NEW! see below how to configure it)
#### Set Admins
You can specify one or more admins with this option: You can specify one or more admins with this option:
```php ```php
...@@ -431,7 +481,7 @@ $telegram->setDownloadPath('yourpath/Download'); ...@@ -431,7 +481,7 @@ $telegram->setDownloadPath('yourpath/Download');
$telegram->setUploadPath('yourpath/Upload'); $telegram->setUploadPath('yourpath/Upload');
``` ```
### Logging ## Logging
Thrown Exceptions are stored in *TelegramException.log* file (in the base directory). Thrown Exceptions are stored in *TelegramException.log* file (in the base directory).
...@@ -451,7 +501,7 @@ $telegram->setLogVerbosity(3); ...@@ -451,7 +501,7 @@ $telegram->setLogVerbosity(3);
## Documentation ## Documentation
Take a look at the repo [Wiki](https://github.com/akalongman/php-telegram-bot/wiki) for further information and tutorial! Take a look at the repo [Wiki](https://github.com/akalongman/php-telegram-bot/wiki) for further information and tutorials!
Feel free to improve! Feel free to improve!
## Projects with this library ## Projects with this library
......
<?xml version="1.0"?>
<ruleset name="Package">
<description>The Package coding standard.</description>
<!-- Exclude folders not containing production code -->
<exclude-pattern type="relative">build/*</exclude-pattern>
<exclude-pattern type="relative">docs/*</exclude-pattern>
<exclude-pattern type="relative">tests/*</exclude-pattern>
<exclude-pattern type="relative">cache/*</exclude-pattern>
<exclude-pattern type="relative">tmp/*</exclude-pattern>
<exclude-pattern type="relative">logs/*</exclude-pattern>
<!-- Exclude 3rd party libraries and Framework code. -->
<exclude-pattern type="relative">vendor/*</exclude-pattern>
<arg name="colors"/>
<!-- Include some additional sniffs from the Generic standard -->
<rule ref="PSR2">
<exclude name="PEAR.Functions.FunctionCallSignature"/>
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceAfterCloseBracket"/>
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property phpcs-only="true" name="lineLimit" value="100"/>
<property phpcbf-only="true" name="lineLimit" value="120"/>
</properties>
</rule>
</ruleset>
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
} }
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.1", "phpunit/phpunit": "~5.2",
"phpspec/phpspec": "~2.1", "squizlabs/php_codesniffer": "~2.5"
"squizlabs/php_codesniffer": "~2.3"
} }
} }
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="pcsg-generated-ruleset">
<description>PHP Code Sniffer</description>
<arg name="colors"/>
<rule ref="PSR2"/>
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="Generic.Files.ByteOrderMark"/>
<rule ref="Generic.Files.LineEndings"/>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.Formatting.SpaceAfterCast.NoSpace">
<type>warning</type>
</rule>
<rule ref="Generic.Functions.CallTimePassByReference"/>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
<rule ref="Generic.Metrics.NestingLevel">
<properties>
<property name="nestingLevel" value="7"/>
</properties>
</rule>
<rule ref="Generic.Metrics.CyclomaticComplexity">
<properties>
<property name="complexity" value="20"/>
<property name="absoluteComplexity" value="40"/>
</properties>
</rule>
<rule ref="Generic.Metrics.CyclomaticComplexity.TooHigh">
<type>warning</type>
</rule>
<rule ref="Generic.Metrics.CyclomaticComplexity.MaxExceeded">
<type>warning</type>
</rule>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Generic.NamingConventions.CamelCapsFunctionName"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.ForbiddenFunctions"/>
<rule ref="Generic.PHP.LowerCaseConstant"/>
<rule ref="Generic.PHP.NoSilencedErrors"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent"/>
<rule ref="Generic.Commenting.Todo.CommentFound">
<message>Please review this TODO comment: %s</message>
<type>warning</type>
</rule>
<rule ref="Generic.Commenting.Fixme.TaskFound">
<message>Please review this FIXME comment: %s</message>
<type>warning</type>
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="200"/>
</properties>
</rule>
<rule ref="Generic.Files.LineLength">
<exclude name="Generic.Files.LineLength.MaxExceeded"/>
<exclude name="Generic.Files.LineLength.TooLong"/>
</rule>
<!--
<rule ref="Generic.Files.LineLength.MaxExceeded">
<message>Line contains %s chars, which is longer than the max limit of %s</message>
<type>warning</type>
</rule>
<rule ref="Generic.Files.LineLength.TooLong">
<message>Line longer than %s characters; contains %s characters</message>
<type>warning</type>
</rule> -->
<rule ref="Generic.Classes.DuplicateClassName"/>
<rule ref="PEAR.Commenting.InlineComment"/>
<rule ref="PEAR.ControlStructures.MultiLineCondition"/>
<rule ref="PEAR.WhiteSpace.ObjectOperatorIndent"/>
<rule ref="MySource.PHP.EvalObjectFactory"/>
<rule ref="MySource.PHP.GetRequestData"/>
<!--
<rule ref="MySource.PHP.ReturnFunctionValue"/>
-->
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
<type>warning</type>
</rule>
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
<!--
<rule ref="Squiz.WhiteSpace.MemberVarSpacing"/>
-->
<rule ref="Squiz.WhiteSpace.OperatorSpacing"/>
<rule ref="Squiz.Scope.StaticThisUsage"/>
</ruleset>
...@@ -236,7 +236,7 @@ class SendtochannelCommand extends AdminCommand ...@@ -236,7 +236,7 @@ class SendtochannelCommand extends AdminCommand
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function executeNoDB() public function executeNoDb()
{ {
$message = $this->getMessage(); $message = $this->getMessage();
$text = trim($message->getText(true)); $text = trim($message->getText(true));
...@@ -274,8 +274,7 @@ class SendtochannelCommand extends AdminCommand ...@@ -274,8 +274,7 @@ class SendtochannelCommand extends AdminCommand
if ($this->sendBack($message, $data)->isOk()) { if ($this->sendBack($message, $data)->isOk()) {
$response = 'Message sent successfully to: ' . $channel; $response = 'Message sent successfully to: ' . $channel;
} else { } else {
$response = $response = 'Message not sent to: ' . $channel . "\n" .
'Message not sent to: ' . $channel . "\n" .
'- Does the channel exist?' . "\n" . '- Does the channel exist?' . "\n" .
'- Is the bot an admin of the channel?'; '- Is the bot an admin of the channel?';
} }
......
...@@ -128,7 +128,7 @@ abstract class Command ...@@ -128,7 +128,7 @@ abstract class Command
public function preExecute() public function preExecute()
{ {
if ($this->need_mysql && !($this->telegram->isDbEnabled() && DB::isDbConnected())) { if ($this->need_mysql && !($this->telegram->isDbEnabled() && DB::isDbConnected())) {
return $this->executeNoDB(); return $this->executeNoDb();
} }
return $this->execute(); return $this->execute();
} }
...@@ -145,7 +145,7 @@ abstract class Command ...@@ -145,7 +145,7 @@ abstract class Command
* *
* @return Entities\ServerResponse * @return Entities\ServerResponse
*/ */
public function executeNoDB() public function executeNoDb()
{ {
//Preparing message //Preparing message
$message = $this->getMessage(); $message = $this->getMessage();
......
...@@ -33,7 +33,7 @@ class GenericmessageCommand extends SystemCommand ...@@ -33,7 +33,7 @@ class GenericmessageCommand extends SystemCommand
* *
* @return boolean * @return boolean
*/ */
public function executeNoDB() public function executeNoDb()
{ {
//Do nothing //Do nothing
return Request::emptyResponse(); return Request::emptyResponse();
......
...@@ -58,7 +58,7 @@ class CancelCommand extends UserCommand ...@@ -58,7 +58,7 @@ class CancelCommand extends UserCommand
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function executeNoDB() public function executeNoDb()
{ {
return $this->hideKeyboard(); return $this->hideKeyboard();
} }
......
...@@ -21,7 +21,7 @@ class Entity ...@@ -21,7 +21,7 @@ class Entity
return $this->bot_name; return $this->bot_name;
} }
public function toJSON() public function toJson()
{ {
$fields = $this->reflect($this); $fields = $this->reflect($this);
$json = json_encode($fields); $json = json_encode($fields);
...@@ -82,6 +82,6 @@ class Entity ...@@ -82,6 +82,6 @@ class Entity
public function __toString() public function __toString()
{ {
return $this->toJSON(); return $this->toJson();
} }
} }
...@@ -174,7 +174,7 @@ class Telegram ...@@ -174,7 +174,7 @@ class Telegram
* *
* @return Telegram * @return Telegram
*/ */
public function enableMySQL(array $credential, $table_prefix = null) public function enableMySql(array $credential, $table_prefix = null)
{ {
$this->pdo = DB::initialize($credential, $this, $table_prefix); $this->pdo = DB::initialize($credential, $this, $table_prefix);
ConversationDB::initializeConversation(); ConversationDB::initializeConversation();
...@@ -380,7 +380,7 @@ class Telegram ...@@ -380,7 +380,7 @@ class Telegram
if ($response->isOk()) { if ($response->isOk()) {
//Process all updates //Process all updates
foreach ((array)$response->getResult() as $result) { foreach ((array) $response->getResult() as $result) {
$this->processUpdate($result); $this->processUpdate($result);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment