From 17c3599e9dd02e1017bbd977a088f88ac186a59b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Noblot Date: Fri, 3 May 2019 15:21:56 +0200 Subject: [PATCH 1/2] php 7.1 version --- composer.json | 2 +- src/FQB.php | 26 +++++++++++++------------- src/GraphEdge.php | 13 +++++++------ src/GraphNode.php | 32 ++++++++++++++++---------------- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/composer.json b/composer.json index 2a655a0..65370ab 100755 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ } ], "require": { - "php": ">=5.4.0" + "php": ">=7.1" }, "require-dev": { "phpunit/phpunit": "~4.0", diff --git a/src/FQB.php b/src/FQB.php index 0fb8f66..404ba93 100644 --- a/src/FQB.php +++ b/src/FQB.php @@ -55,7 +55,7 @@ class FQB * @param array $config An array of config options. * @param string|null $graphEndpoint The name of the Graph API endpoint. */ - public function __construct(array $config = [], $graphEndpoint = '') + public function __construct(array $config = [], ?string $graphEndpoint = null) { if (isset($graphEndpoint)) { $this->graphNode = new GraphNode($graphEndpoint); @@ -87,7 +87,7 @@ public function __construct(array $config = [], $graphEndpoint = '') * * @return FQB */ - public function node($graph_node_name) + public function node(string $graph_node_name): self { return new static($this->config, $graph_node_name); } @@ -100,7 +100,7 @@ public function node($graph_node_name) * * @return GraphEdge */ - public function edge($edgeName, array $fields = []) + public function edge(string $edgeName, array $fields = []): GraphEdge { return new GraphEdge($edgeName, $fields); } @@ -112,7 +112,7 @@ public function edge($edgeName, array $fields = []) * * @return FQB */ - public function fields($fields) + public function fields($fields): self { if (!is_array($fields)) { $fields = func_get_args(); @@ -130,7 +130,7 @@ public function fields($fields) * * @return FQB */ - public function accessToken($accessToken) + public function accessToken(string $accessToken): self { $this->graphNode->modifiers([ GraphNode::PARAM_ACCESS_TOKEN => $accessToken, @@ -146,7 +146,7 @@ public function accessToken($accessToken) * * @return FQB */ - public function graphVersion($graphVersion) + public function graphVersion(string $graphVersion): self { $this->graphVersion = $graphVersion; @@ -160,7 +160,7 @@ public function graphVersion($graphVersion) * * @return FQB */ - public function limit($limit) + public function limit(int $limit): self { $this->graphNode->limit($limit); @@ -174,7 +174,7 @@ public function limit($limit) * * @return FQB */ - public function modifiers(array $data) + public function modifiers(array $data): self { $this->graphNode->modifiers($data); @@ -186,7 +186,7 @@ public function modifiers(array $data) * * @return string */ - public function asUrl() + public function asUrl(): string { return $this->getHostname().$this->asEndpoint(); } @@ -196,11 +196,11 @@ public function asUrl() * * @return string */ - public function asEndpoint() + public function asEndpoint(): string { $graphVersionPrefix = ''; if ($this->graphVersion) { - $graphVersionPrefix = '/'.$this->graphVersion; + $graphVersionPrefix = "/{$this->graphVersion}"; } return $graphVersionPrefix.$this->graphNode->asUrl($this->appSecret); @@ -211,7 +211,7 @@ public function asEndpoint() * * @return string */ - public function __toString() + public function __toString(): string { return $this->asUrl(); } @@ -221,7 +221,7 @@ public function __toString() * * @return string */ - private function getHostname() + private function getHostname(): string { if ($this->enableBetaMode === true) { return static::BASE_GRAPH_URL_BETA; diff --git a/src/GraphEdge.php b/src/GraphEdge.php index 34eae96..af0f1dd 100755 --- a/src/GraphEdge.php +++ b/src/GraphEdge.php @@ -1,4 +1,5 @@ -modifiers) === 0) { return; @@ -69,7 +70,7 @@ public function compileModifiers() /** * Compile the field values. */ - public function compileFields() + public function compileFields(): void { if (count($this->fields) === 0) { return; @@ -89,7 +90,7 @@ public function compileFields() * * @return string */ - public function compileUrl() + public function compileUrl(): string { $append = ''; if (count($this->compiledValues) > 0) { diff --git a/src/GraphNode.php b/src/GraphNode.php index 3596a66..37a3b3a 100755 --- a/src/GraphNode.php +++ b/src/GraphNode.php @@ -65,7 +65,7 @@ class GraphNode * @param array $fields * @param int $limit */ - public function __construct($name, $fields = [], $limit = 0) + public function __construct(string $name, array $fields = [], int $limit = 0) { $this->name = $name; $this->fields($fields); @@ -81,7 +81,7 @@ public function __construct($name, $fields = [], $limit = 0) * * @return GraphNode */ - public function modifiers(array $data) + public function modifiers(array $data): self { $this->modifiers = array_merge($this->modifiers, $data); @@ -93,7 +93,7 @@ public function modifiers(array $data) * * @return array */ - public function getModifiers() + public function getModifiers(): array { return $this->modifiers; } @@ -105,9 +105,9 @@ public function getModifiers() * * @return mixed|null */ - public function getModifier($key) + public function getModifier(string $key) { - return isset($this->modifiers[$key]) ? $this->modifiers[$key] : null; + return $this->modifiers[$key] ?? null; } /** @@ -117,7 +117,7 @@ public function getModifier($key) * * @return GraphNode */ - public function limit($limit) + public function limit(int $limit): self { return $this->modifiers([ static::PARAM_LIMIT => $limit, @@ -129,7 +129,7 @@ public function limit($limit) * * @return int|null */ - public function getLimit() + public function getLimit(): ?int { return $this->getModifier(static::PARAM_LIMIT); } @@ -141,7 +141,7 @@ public function getLimit() * * @return GraphNode */ - public function fields($fields) + public function fields($fields): self { if (!is_array($fields)) { $fields = func_get_args(); @@ -157,7 +157,7 @@ public function fields($fields) * * @return array */ - public function getFields() + public function getFields(): array { return $this->fields; } @@ -165,7 +165,7 @@ public function getFields() /** * Clear the compiled values. */ - public function resetCompiledValues() + public function resetCompiledValues(): void { $this->compiledValues = []; } @@ -173,7 +173,7 @@ public function resetCompiledValues() /** * Compile the modifier values. */ - public function compileModifiers() + public function compileModifiers(): void { if (count($this->modifiers) === 0) { return; @@ -185,7 +185,7 @@ public function compileModifiers() /** * Compile the field values. */ - public function compileFields() + public function compileFields(): void { if (count($this->fields) === 0) { return; @@ -199,7 +199,7 @@ public function compileFields() * * @return string */ - public function compileUrl() + public function compileUrl(): string { $append = ''; if (count($this->compiledValues) > 0) { @@ -216,7 +216,7 @@ public function compileUrl() * * @return string */ - public function asUrl($appSecret = null) + public function asUrl(?string $appSecret = null): string { $this->resetCompiledValues(); @@ -235,7 +235,7 @@ public function asUrl($appSecret = null) * * @return string */ - public function __toString() + public function __toString(): string { return $this->asUrl(); } @@ -245,7 +245,7 @@ public function __toString() * * @param string $appSecret */ - private function addAppSecretProofModifier($appSecret) + private function addAppSecretProofModifier(string $appSecret): void { $accessToken = $this->getModifier(static::PARAM_ACCESS_TOKEN); if (!$accessToken) { From d045a569786d3d23e6dd39217e82440d1b557c73 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Noblot Date: Fri, 3 May 2019 15:35:47 +0200 Subject: [PATCH 2/2] change construct FQB cause graphEndpoint the doc says null but can cause NULL pointer on $this->graphNode who not can be NULLABLE on doc --- src/FQB.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/FQB.php b/src/FQB.php index 404ba93..88ab46b 100644 --- a/src/FQB.php +++ b/src/FQB.php @@ -53,13 +53,11 @@ class FQB /** * @param array $config An array of config options. - * @param string|null $graphEndpoint The name of the Graph API endpoint. + * @param string $graphEndpoint The name of the Graph API endpoint. */ - public function __construct(array $config = [], ?string $graphEndpoint = null) + public function __construct(array $config = [], string $graphEndpoint = '') { - if (isset($graphEndpoint)) { - $this->graphNode = new GraphNode($graphEndpoint); - } + $this->graphNode = new GraphNode($graphEndpoint); $this->config = $config;