Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into Parser-opti…
Browse files Browse the repository at this point in the history
…mization

# Conflicts:
#	tests/TestCase/AnalyzerTest.php
#	tests/TestCase/PageTest.php
  • Loading branch information
grgk committed Oct 23, 2019
2 parents 279c1ae + d2660bc commit a3083dc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 42 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ dist: trusty
php:
- 7.1
- 7.2
- 7.3

before_script:
composer install
- composer install
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build

addons:
sonarcloud:
Expand All @@ -16,3 +20,6 @@ addons:
script:
- vendor/bin/phpunit --coverage-clover build/logs/phpunit/clover.xml --log-junit build/logs/phpunit/junit.xml --coverage-xml build/logs/phpunit/coverage/xml --coverage-html build/logs/phpunit/coverage/html
- sonar-scanner

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
18 changes: 0 additions & 18 deletions sonarphp-xml-patcher.py

This file was deleted.

18 changes: 8 additions & 10 deletions src/Analyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SeoAnalyzer;

use InvalidArgumentException;
use ReflectionException;
use SeoAnalyzer\HttpClient\Client;
use SeoAnalyzer\HttpClient\ClientInterface;
use SeoAnalyzer\HttpClient\Exception\HttpException;
Expand Down Expand Up @@ -54,8 +56,7 @@ public function __construct(Page $page = null, ClientInterface $client = null)
* @param string|null $keyword
* @param string|null $locale
* @return array
* @throws HttpException
* @throws \ReflectionException
* @throws ReflectionException
*/
public function analyzeUrl(string $url, string $keyword = null, string $locale = null): array
{
Expand All @@ -75,8 +76,7 @@ public function analyzeUrl(string $url, string $keyword = null, string $locale =
* @param string $filename
* @param string|null $locale
* @return array
* @throws HttpException
* @throws \ReflectionException
* @throws ReflectionException
*/
public function analyzeFile(string $filename, string $locale = null): array
{
Expand All @@ -89,13 +89,12 @@ public function analyzeFile(string $filename, string $locale = null): array
* Starts analysis of a Page.
*
* @return array
* @throws HttpException
* @throws \ReflectionException
* @throws ReflectionException
*/
public function analyze()
{
if (empty($this->page)) {
throw new \InvalidArgumentException('No Page to analyze');
throw new InvalidArgumentException('No Page to analyze');
}
$translator = $this->getTranslator($this->locale);
$results = [];
Expand All @@ -122,8 +121,7 @@ public function analyze()
* Returns available metrics list for a Page
*
* @return array
* @throws HttpException
* @throws \ReflectionException
* @throws ReflectionException
*/
public function getMetrics(): array
{
Expand All @@ -134,7 +132,7 @@ public function getMetrics(): array
* Returns file related metrics.
*
* @return array
* @throws \ReflectionException
* @throws ReflectionException
*/
public function getFilesMetrics(): array
{
Expand Down
33 changes: 21 additions & 12 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Page
/**
* @var array Web page factors values
*/
public $factors;
public $factors = [];

/**
* @var ClientInterface
Expand Down Expand Up @@ -290,7 +290,7 @@ public function setUpContentFactors()
}

/**
* Sets up page content factors keyword related .
* Sets up page content factors keyword related.
*
* @param string $keyword
*/
Expand Down Expand Up @@ -399,22 +399,31 @@ public function setUpMetrics(array $config)
*/
public function setFactor(string $name, $value)
{
$dots = explode('.', $name);
if (count($dots) > 1) {
$last = &$this->factors[$dots[0]];
foreach ($dots as $k => $dot) {
if ($k == 0) {
continue;
}
$last = &$last[$dot];
}
$last = $value;
if (count(explode('.', $name)) > 1) {
$this->setArrayByDot($this->factors, $name, $value);
} else {
$this->factors[$name] = $value;
}
return $this->factors;
}

/**
* Sets array values using string with dot notation.
*
* @param array $array Array to be updated
* @param string $path Dot notated string
* @param mixed $val Value to be set in array
* @return array
*/
protected function setArrayByDot(array &$array, string $path, $val)
{
$loc = &$array;
foreach (explode('.', $path) as $step) {
$loc = &$loc[$step];
}
return $loc = $val;
}

/**
* Sets multiple page factors values at once.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace Tests;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase as PhpUnitTestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
Expand All @@ -26,7 +27,7 @@ public function setUp()

/**
* @param string|null $response Response body content to be returned
* @return \PHPUnit\Framework\MockObject\MockObject|ClientInterface
* @return MockObject|ClientInterface
*/
public function getClientMock(string $response = null)
{
Expand Down

0 comments on commit a3083dc

Please sign in to comment.