Skip to content

Commit

Permalink
Code rewrited on PSR-2 standard. Added CONTRIBUTING.md for contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
akalongman committed Jul 6, 2015
1 parent e12787a commit 80ce398
Show file tree
Hide file tree
Showing 19 changed files with 1,269 additions and 1,385 deletions.
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Contributing
-------------

Before you contribute code to php-telegram-bot, please make sure it conforms to the PHPCS coding standard and that the php-telegram-bot unit tests still pass. The easiest way to contribute is to work on a checkout of the repository, or your own fork, rather than an installed PEAR version. If you do this, you can run the following commands to check if everything is ready to submit:

cd php-telegram-bot
composer update
vendor/bin/phpcs --report=full --extensions=php -p --standard=build/phpcs .

Which should give you no output, indicating that there are no coding standard errors. And then:

phpunit

Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ Create set.php and put:
```php
<?php

$loader = require __DIR__.'/vendor/autoload.php';
$loader = require \_\_DIR\_\_.'/vendor/autoload.php';

$API_KEY = 'your_bot_api_key';
$API\_KEY = 'your\_bot\_api\_key';
$BOT_NAME = 'namebot';

try {
// create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
$telegram = new Longman\TelegramBot\Telegram($API\_KEY, $BOT\_NAME);

// set webhook
echo $telegram->setWebHook('https://yourdomain/yourpath_to_hook.php');
Expand All @@ -123,9 +123,9 @@ After create hook.php and put:
```php
<?php

$loader = require __DIR__.'/vendor/autoload.php';
$loader = require \_\_DIR\_\_.'/vendor/autoload.php';

$API_KEY = 'your_bot_api_key';
$API\_KEY = 'your\_bot\_api\_key';
$BOT_NAME = 'namebot';

try {
Expand Down Expand Up @@ -154,11 +154,19 @@ $telegram->enableMySQL($credentials);

This code is available on [Github][0]. Pull requests are welcome.


Troubleshooting
---------------
-------------

If you like living on the edge, please report any bugs you find on the [PHP Telegram Bot issues](https://github.com/akalongman/php-telegram-bot/issues) page.


Contributing
-------------

See [CONTRIBUTING.md](CONTRIBUTING.md) for information.


## Credits

Created by [Avtandil Kikabidze][1].
Expand Down
74 changes: 16 additions & 58 deletions build/phpcs/ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,67 +1,25 @@
<?xml version="1.0"?>
<ruleset name="Package">
<description>The Package coding standard.</description>
<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 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>
<!-- Exclude 3rd party libraries and Framework code. -->
<exclude-pattern type="relative">vendor/*</exclude-pattern>

<!-- Include all sniffs in an external standard directory -->
<!-- Include all sniffs in an external standard directory -->

<!-- Include some additional sniffs from the Generic standard -->
<!-- Include some additional sniffs from the Generic standard -->

<rule ref="PEAR.Classes.ClassDeclaration"/>
<rule ref="Squiz.Classes.SelfMemberReference"/>

<rule ref="PEAR.Commenting.InlineComment"/>

<rule ref="Generic.Files.LineEndings"/>

<rule ref="PEAR.Formatting.MultiLineAssignment"/>

<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>

<rule ref="PEAR.NamingConventions.ValidClassName"/>

<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>

<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.ForbiddenFunctions"/>

<rule ref="Squiz.Operators.IncrementDecrementUsage">
<exclude name="Squiz.Operators.IncrementDecrementUsage.processAssignment"/>
</rule>

<rule ref="Squiz.Scope.StaticThisUsage"/>

<rule ref="Squiz.WhiteSpace.ScopeClosingBrace"/>

<!-- Lines can be 85 chars long, but never show errors -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="150"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>

<!-- Use Unix newlines -->
<rule ref="Generic.Files.LineEndings">
<properties>
<property name="eolChar" value="\n"/>
</properties>
</rule>

<!-- This message is not required as spaces are allowed for alignment -->
<rule ref="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma">
<severity>0</severity>
</rule>
<rule ref="PSR2">
<exclude name="PEAR.Functions.FunctionCallSignature"/>
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceAfterCloseBracket"/>
</rule>

</ruleset>
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

135 changes: 72 additions & 63 deletions src/Command.php
Original file line number Diff line number Diff line change
@@ -1,78 +1,87 @@
<?php

/*
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
*/
namespace Longman\TelegramBot;

use Longman\TelegramBot\Entities\Update;

abstract class Command
{
protected $telegram;
protected $update;
protected $message;
protected $command;

protected $description = 'Command help';
protected $usage = 'Command usage';
protected $version = '1.0.0';
protected $enabled = true;
protected $name = '';

public function __construct(Telegram $telegram) {
$this->telegram = $telegram;
}

public function setUpdate(Update $update) {
$this->update = $update;
$this->message = $this->update->getMessage();
return $this;
}


public abstract function execute();


public function getUpdate() {
return $this->update;
}

public function getMessage() {
return $this->message;
}


public function getTelegram() {
return $this->telegram;
}

public function setCommand($command) {
$this->command = $command;
return $this;
}

public function getUsage() {
return $this->usage;
}

public function getVersion() {
return $this->version;
}

public function getDescription() {
return $this->description;
}

public function getName() {
return $this->name;
}

public function isEnabled() {
return $this->enabled;
}
protected $telegram;
protected $update;
protected $message;
protected $command;

protected $description = 'Command help';
protected $usage = 'Command usage';
protected $version = '1.0.0';
protected $enabled = true;
protected $name = '';

public function __construct(Telegram $telegram)
{
$this->telegram = $telegram;
}

public function setUpdate(Update $update)
{
$this->update = $update;
$this->message = $this->update->getMessage();
return $this;
}

abstract public function execute();

public function getUpdate()
{
return $this->update;
}

public function getMessage()
{
return $this->message;
}

public function getTelegram()
{
return $this->telegram;
}

public function setCommand($command)
{
$this->command = $command;
return $this;
}

public function getUsage()
{
return $this->usage;
}

public function getVersion()
{
return $this->version;
}

public function getDescription()
{
return $this->description;
}

public function getName()
{
return $this->name;
}

public function isEnabled()
{
return $this->enabled;
}
}
Loading

0 comments on commit 80ce398

Please sign in to comment.