Skip to content

Commit

Permalink
Merge pull request #10 from Chris53897/feature/strong-types
Browse files Browse the repository at this point in the history
feat: modernize, add strong types, add phpstan, add php-cs-fixer, get…
  • Loading branch information
neoteknic authored Aug 24, 2022
2 parents f051ccb + de8ed2f commit 6755f07
Show file tree
Hide file tree
Showing 175 changed files with 1,384 additions and 4,244 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Tests"

on:
push:
pull_request:

permissions:
contents: read

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.0', '8.1', '8.2']

name: "Tests"

steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: pcov
- run: composer install --no-progress
- run: composer run-script phpstan
- run: composer run-script phpunit
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ composer.lock
*.buildpath
*.prefs

.phpunit.result.cache
.php-cs-fixer.cache

.settings/org.eclipse.wst.common.project.facet.core.xml
.project
18 changes: 18 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

$finder = PhpCsFixer\Finder::create()
->files()
->name('*.php')
->in(__DIR__.'/examples')
->in(__DIR__.'/library')
->in(__DIR__.'/tests')
;

$config = new PhpCsFixer\Config();
return $config
->setRiskyAllowed(false)
->setRules([
'@PSR2' => true,
])
->setFinder($finder)
;
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Interested in API docs? You can check out the [Philips API documentation](http:/

## Requirements

* PHP 7.1+
* PHP 8.0+
* cURL extension (optional)

For old php support please use the original package sqmk/Phue
Expand Down Expand Up @@ -512,7 +512,7 @@ Number of bridges found: 1

The internal IP address(es) listed in the results is what you need for the Phue client.

If the script provided doesn't find your bridge, or if you don't have internet connection on your network, I have created a wiki page that describes a few other convenient ways of finding it: [Finding Philips Hue bridge on network](/sqmk/Phue/wiki/Finding-Philips-Hue-bridge-on-network).
If the script provided doesn't find your bridge, or if you don't have internet connection on your network, I have created a wiki page that describes a few other convenient ways of finding it: [Finding Philips Hue bridge on network](https://github.com/neoteknic/Phue/wiki/Finding-Philips-Hue-bridge-on-your-network).

### Authentication / Creating a User

Expand Down Expand Up @@ -576,3 +576,10 @@ Now that you have found and registered new lights with the bridge, you can now m
### More examples

If you are interested in seeing examples for all sorts of commands, check out the ```examples``` directory.

### Run tests PhpStan and PhpUnit

```
composer run-script phpstan
composer run-script phpunit
```
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{

"name": "neoteknic/phue",
"description": "Phue - Philips Hue PHP client - Fork by Neoteknic - extra features",
"type": "library",
Expand Down Expand Up @@ -27,8 +26,10 @@
"php": "^8.0"
},
"require-dev": {
"mockery/mockery": "1.*",
"phpunit/phpunit": "9.*"
"mockery/mockery": "^1.5",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.8",
"friendsofphp/php-cs-fixer": "^3.9.5"
},
"suggest": {
"ext-curl": "Allows usage of cURL transport adapter"
Expand All @@ -43,5 +44,9 @@
"bin/phue-bridge-finder",
"bin/phue-light-finder",
"bin/phue-list-lights"
]
],
"scripts": {
"phpstan": "phpstan analyse library --no-progress --level=6",
"phpunit": "phpunit "
}
}
2 changes: 1 addition & 1 deletion examples/all-lights-colorloop.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: All lights to colorloop effect.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/all-lights-scene.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: All lights to a scene.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/candle-effect.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Candle effect.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/create-group.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Create test group.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/create-rule.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Create test rule.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/create-scene-state.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Create test scene, set state, and assign to group.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/create-sensor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Create test sensor.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/delete-all-schedules.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Delete all schedules.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/delete-group.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Delete test group.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/delete-scene.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Delete test scene.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/delete-schedule.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Delete a schedule.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/list-groups.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: List groups registered on bridge.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/list-lights.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: List lights registered on bridge.
*
Expand Down
4 changes: 2 additions & 2 deletions examples/list-rules.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: List rules.
*
Expand All @@ -11,7 +11,7 @@
echo 'Listing rules:', "\n";

foreach ($client->getRules() as $rule) {
echo "\t", "#{$rule->getId()} - {$rule->getName()}", "\n", "\t\t", "Last Triggered Time: {$rule->getLastTriggeredTime()}", "\n", "\t\t", "Created date: {$rule->getCreatedDate()}", "\n", "\t\t", "Times triggered: {$rule->getTriggeredCount()}", "\n", "\t\t", "Owner: {$rule->getOwner()}", "\n", "\t\t", "Status: ", $rule->isEnabled() ? 'Yes' : 'No', "\n";
echo "\t", "#{$rule->getId()} - {$rule->getName()}", "\n", "\t\t", "Last Triggered Time: {$rule->getLastTriggeredTime()}", "\n", "\t\t", "Created date: {$rule->getCreateDate()}", "\n", "\t\t", "Times triggered: {$rule->getTriggeredCount()}", "\n", "\t\t", "Owner: {$rule->getOwner()}", "\n", "\t\t", "Status: ", $rule->isEnabled() ? 'Yes' : 'No', "\n";

echo "\t\t", "Conditions: ", "\n";
foreach ($rule->getConditions() as $condition) {
Expand Down
2 changes: 1 addition & 1 deletion examples/list-scenes.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: List scenes registered on bridge.
*
Expand Down
2 changes: 2 additions & 0 deletions examples/list-schedules.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
*/
require_once 'common.php';

/** @noinspection PhpUndefinedVariableInspection */
$client = new \Phue\Client($hueHost, $hueUsername);

echo 'Listing schedules:', "\n";

# TODO $schedule ?
$cmd = $schedule->getCommand();
foreach ($client->getSchedules() as $schedule) {
echo "\t", "#{$schedule->getId()} - {$schedule->getName()}", "\n", "\t\t", "Time scheduled: {$schedule->getTime()}", "\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/list-sensors.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: List sensors.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/list-timezones.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: List timezones.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/list-users.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: List users.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/schedule-all-lights-change.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Schedule all lights to change.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/schedule-group-state.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Schedule a specific groups state.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/schedule-recurring.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Schedule all lights to change, recurring date.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/set-bridge-config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Set bridge config.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/show-bridge-config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Show bridge config.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/update-bridge.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Update bridge.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/update-rule.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Update test rule.
*
Expand Down
2 changes: 1 addition & 1 deletion examples/update-sensor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpUndefinedVariableInspection */
/**
* Example: Update test sensor.
*
Expand Down
Loading

0 comments on commit 6755f07

Please sign in to comment.