Skip to content

Commit 5867f10

Browse files
committed
Validate composer.json 👷 and more...
1 parent 29e3caf commit 5867f10

File tree

9 files changed

+204
-157
lines changed

9 files changed

+204
-157
lines changed

Block/Snowflake.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
/**
3+
* Copyright © OpenGento, All rights reserved.
4+
* See LICENSE bundled with this library for license details.
5+
*/
26
declare(strict_types=1);
37

48
namespace Opengento\Snowflake\Block;
@@ -9,62 +13,65 @@
913

1014
class Snowflake extends Template
1115
{
12-
protected ScopeConfigInterface $snowflakeConfig;
13-
protected SnowflakeConfig $config;
16+
protected SnowflakeConfig $snowflakeConfig;
17+
protected ScopeConfigInterface $scopeConfig;
1418

1519
public function __construct(
16-
ScopeConfigInterface $scopeConfig,
17-
SnowflakeConfig $snowflakeConfig,
1820
Template\Context $context,
21+
SnowflakeConfig $snowflakeConfig,
1922
array $data = []
2023
) {
21-
$this->SnowflakeConfig = $snowflakeConfig;
22-
$this->scopeConfig = $scopeConfig;
24+
$this->snowflakeConfig = $snowflakeConfig;
2325
parent::__construct($context, $data);
2426
}
2527

2628
public function getSnowflakeChar(): string
2729
{
28-
return $this->SnowflakeConfig->getSnowflakeChar();
30+
return $this->snowflakeConfig->getSnowflakeChar();
31+
}
32+
33+
public function getSnowflakeVSpeed(): string
34+
{
35+
return $this->snowflakeConfig->getSnowflakeVSpeed();
2936
}
3037

31-
public function getSnowflakeVSpeed() : string
38+
public function getSnowflakeHSpeed(): string
3239
{
33-
return $this->SnowflakeConfig->getSnowflakeVSpeed();
40+
return $this->snowflakeConfig->getSnowflakeHSpeed();
3441
}
3542

36-
public function getSnowflakeHSpeed() : string
43+
public function getSnowflakeRotSpeed(): string
3744
{
38-
return $this->SnowflakeConfig->getSnowflakeHSpeed();
45+
return $this->snowflakeConfig->getSnowflakeRotSpeed();
3946
}
4047

41-
public function getSnowflakeRotSpeed() : string
48+
public function getSnowflakeQty(): int
4249
{
43-
return $this->SnowflakeConfig->getSnowflakeRotSpeed();
50+
return (int)$this->snowflakeConfig->getSnowflakeQty();
4451
}
4552

46-
public function getSnowflakeQty() : int
53+
public function getSnowflakeMinSize(): int
4754
{
48-
return (int)$this->SnowflakeConfig->getSnowflakeQty();
55+
return (int)$this->snowflakeConfig->getSnowflakeMinSize();
4956
}
5057

51-
public function getSnowflakeMinSize() : int
58+
public function getSnowflakeMaxSize(): int
5259
{
53-
return (int)$this->SnowflakeConfig->getSnowflakeMinSize();
60+
return (int)$this->snowflakeConfig->getSnowflakeMaxSize();
5461
}
5562

56-
public function getSnowflakeMaxSize() : int
63+
public function isForceSnow(): bool
5764
{
58-
return (int)$this->SnowflakeConfig->getSnowflakeMaxSize();
65+
return $this->snowflakeConfig->isForceSnow();
5966
}
6067

61-
public function getSnowflakeForce() : string
68+
public function isApiEnable(): bool
6269
{
63-
return $this->SnowflakeConfig->getSnowflakeForce();
70+
return $this->snowflakeConfig->isApiEnable();
6471
}
6572

6673
public function getAjaxUrl(): string
6774
{
68-
return $this->SnowflakeConfig->getAjaxUrl();
75+
return $this->snowflakeConfig->getAjaxUrl();
6976
}
7077
}

Controller/Index/Meteo.php renamed to Controller/Api/Meteo.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Opengento\Snowflake\Controller\Index;
8+
namespace Opengento\Snowflake\Controller\Api;
99

1010
use Magento\Framework\App\Action\Action;
1111
use Magento\Framework\App\Action\Context;
@@ -32,11 +32,15 @@ public function __construct(
3232
*/
3333
public function execute()
3434
{
35-
$lat = $this->getRequest()->getParam('lat');
36-
$lon = $this->getRequest()->getParam('lon');
35+
$isSnowing = ['is_snowing' => '0'];
3736

38-
return $this->resultJsonFactory->create()->setData(
39-
['is_snowing' => $this->api->isSnowing($lat, $lon)]
40-
);
37+
$lat = $this->getRequest()->getParam('lat') ?? '';
38+
$lon = $this->getRequest()->getParam('lon') ?? '';
39+
40+
if ($lat && $lon) {
41+
$isSnowing = ['is_snowing' => $this->api->isSnowing($lat, $lon)];
42+
}
43+
44+
return $this->resultJsonFactory->create()->setData($isSnowing);
4145
}
4246
}

Model/Config/Backend/EmojiConverter.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<?php
2-
declare(strict_types = 1);
2+
/**
3+
* Copyright © OpenGento, All rights reserved.
4+
* See LICENSE bundled with this library for license details.
5+
*/
6+
declare(strict_types=1);
37

48
namespace Opengento\Snowflake\Model\Config\Backend;
59

6-
use Magento\Config\Model\Config\Backend\Serialized\ArraySerialized;
10+
use Magento\Framework\App\Config\Data\ProcessorInterface;
11+
use Magento\Framework\App\Config\Value;
712

8-
class EmojiConverter extends \Magento\Framework\App\Config\Value implements \Magento\Framework\App\Config\Data\ProcessorInterface
13+
class EmojiConverter extends Value implements ProcessorInterface
914
{
1015
/**
1116
* Unset array element with '__empty' key

Model/Config/Snowflake.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212

1313
class Snowflake
1414
{
15-
public const AJAX_URL = 'opengento_snowflake/index/meteo';
15+
public const AJAX_URL = 'opengento_snowflake/api/meteo';
1616

17-
private const CONFIG_PATH_SNOWFLAKE_ENABLE = 'opengento/snowflake/enable';
17+
private const CONFIG_PATH_SNOWFLAKE_ENABLE = 'snowflake/general/enable';
1818
private const CONFIG_PATH_SNOWFLAKE_CHAR = 'snowflake/general/icon';
1919
private const CONFIG_PATH_SNOWFLAKE_V_SPEED = 'snowflake/general/vspeed';
2020
private const CONFIG_PATH_SNOWFLAKE_H_SPEED = 'snowflake/general/hspeed';
2121
private const CONFIG_PATH_SNOWFLAKE_ROT_SPEED = 'snowflake/general/rotspeed';
22-
private const CONFIG_PATH_SNOWFLAKE_OPENWEATHERMAP_API_KEY = 'opengento/snowflake/api_key';
22+
private const CONFIG_PATH_SNOWFLAKE_OPENWEATHERMAP_ENABLE = 'snowflake/general/enable_api';
23+
private const CONFIG_PATH_SNOWFLAKE_OPENWEATHERMAP_API_KEY = 'snowflake/general/api_key';
2324
private const CONFIG_PATH_SNOWFLAKE_MIN_SIZE = 'snowflake/general/max_size';
2425
private const CONFIG_PATH_SNOWFLAKE_MAX_SIZE = 'snowflake/general/min_size';
2526
private const CONFIG_PATH_SNOWFLAKE_QTY = 'snowflake/general/qty';
26-
private const CONFIG_PATH_SNOWFLAKE_FORCE = 'snowflake/api/force';
27+
private const CONFIG_PATH_SNOWFLAKE_FORCE = 'snowflake/general/force';
2728

2829
private ScopeConfigInterface $scopeConfig;
2930

@@ -72,9 +73,18 @@ public function getSnowflakeMaxSize(?int $scopeId = null): string
7273
return $this->scopeConfig->getValue(self::CONFIG_PATH_SNOWFLAKE_MAX_SIZE, ScopeInterface::SCOPE_STORE, $scopeId) ?? '';
7374
}
7475

75-
public function getSnowflakeForce(?int $scopeId = null): string
76+
public function isForceSnow(?int $scopeId = null): bool
7677
{
77-
return (string)$this->scopeConfig->getValue(self::CONFIG_PATH_SNOWFLAKE_FORCE, ScopeInterface::SCOPE_STORE, $scopeId);
78+
return $this->scopeConfig->isSetFlag(self::CONFIG_PATH_SNOWFLAKE_FORCE, ScopeInterface::SCOPE_STORE, $scopeId);
79+
}
80+
81+
public function isApiEnable(?int $scopeId = null): bool
82+
{
83+
return $this->scopeConfig->isSetFlag(
84+
self::CONFIG_PATH_SNOWFLAKE_OPENWEATHERMAP_ENABLE,
85+
ScopeInterface::SCOPE_STORE,
86+
$scopeId
87+
);
7888
}
7989

8090
public function getApiKey(?int $scopeId = null): string

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
[![Packagist](https://img.shields.io/packagist/dt/opengento/module-snowflake.svg?style=flat-square)](https://packagist.org/packages/opengento/module-snowflake/stats)
66
[![Packagist](https://img.shields.io/packagist/dm/opengento/module-snowflake.svg?style=flat-square)](https://packagist.org/packages/opengento/module-snowflake/stats)
77

8-
This module adds ❄️️ based on local meteo.
8+
This fun module adds ❄️️ on your website all the time or based on your visitor outside weather.
99

1010
- [Setup](#setup)
1111
- [Composer installation](#composer-installation)
12-
- [Setup the module](#setup-the-snowflake)
12+
- [Setup the module](#setup-the-module)
1313
- [Features](#features)
1414
- [Settings](#settings)
1515
- [Documentation](#documentation)
@@ -21,19 +21,19 @@ This module adds ❄️️ based on local meteo.
2121

2222
Magento 2 Open Source or Commerce edition is required.
2323

24-
### Composer installation
24+
### Composer installation
2525

2626
Run the following composer command:
2727

28-
```
28+
```shell
2929
composer require opengento/module-snowflake
3030
```
3131

3232
### Setup the module
3333

3434
Run the following magento command:
3535

36-
```
36+
```shell
3737
bin/magento setup:upgrade
3838
```
3939

@@ -45,21 +45,27 @@ bin/magento setup:upgrade
4545

4646
Do you like the snow? Do you like to feel the same weather on your favorite website? Try this plugin and get the snow along your local meteo!
4747

48-
## Settings
48+
Require: [OpenWeatherMap API key](https://openweathermap.org/).
49+
50+
### Force Snowflake
4951

50-
The configuration for this module is available in `Stores > Configuration > General > Snowflake`.
52+
It doesn't snow everywhere, so you can force snow.
5153

52-
## Documentation
54+
### Hacking Snowflake
55+
56+
You don't like snow, no problem, Snowflake can make it rain [cookies](https://twitter.com/MehdiChch/status/1505649692755079169), [hot-dog](https://twitter.com/MehdiChch/status/1505258061249884160) or whatever you want.
57+
58+
## Settings
5359

54-
Enable the module in the configuration panel to enable the snowflake based on the local meteo.
60+
The configuration for this module is available in `Stores > Configuration > General > ❄️ Snowflake`.
5561

5662
## Support
5763

5864
Raise a new [request](https://github.com/opengento/magento2-snowflake/issues) to the issue tracker.
5965

6066
## Authors
6167

62-
- **Opengento Community** - *Lead* - [![Twitter Follow](https://img.shields.io/twitter/follow/opengento.svg?style=social)](https://twitter.com/opengento)
68+
- **OpenGento Community** - *Lead* - [![Twitter Follow](https://img.shields.io/twitter/follow/opengento.svg?style=social)](https://twitter.com/opengento)
6369
- **Contributors** - *Contributor* - [![GitHub contributors](https://img.shields.io/github/contributors/opengento/magento2-snowflake.svg?style=flat-square)](https://github.com/opengento/magento2-snowflake/graphs/contributors)
6470

6571
## License

Service/OpenWeatherMapApi.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
class OpenWeatherMapApi
1616
{
17+
// Manage all Group 6xx: Snow
18+
// https://openweathermap.org/weather-conditions
19+
public const WEATHER_CONDITION = 'snow';
20+
1721
// Language of data (try your own language here!):
1822
protected string $lang = 'en';
1923

@@ -31,7 +35,7 @@ public function __construct(
3135
/**
3236
* @throws OpenWeatherMap\Exception
3337
*/
34-
public function isSnowing($lat, $lon): bool
38+
public function isSnowing(string $lat, string $lon): bool
3539
{
3640
$apiKey = $this->config->getApiKey();
3741

@@ -42,6 +46,6 @@ public function isSnowing($lat, $lon): bool
4246

4347
$weather = $owm->getWeather(['lat' => $lat, 'lon' => $lon], $this->lang, $this->units);
4448

45-
return 'snow' === $weather->weather->description;
49+
return static::WEATHER_CONDITION === $weather->weather->description;
4650
}
4751
}

0 commit comments

Comments
 (0)