-
-
-
diff --git a/docs/conf.py b/docs/conf.py
new file mode 100644
index 0000000..e5604c6
--- /dev/null
+++ b/docs/conf.py
@@ -0,0 +1,56 @@
+# Configuration file for the Sphinx documentation builder.
+#
+# This file only contains a selection of the most common options. For a full
+# list see the documentation:
+# https://www.sphinx-doc.org/en/master/usage/configuration.html
+
+# -- Path setup --------------------------------------------------------------
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+# import os
+# import sys
+# sys.path.insert(0, os.path.abspath('.'))
+
+# -- Project information -----------------------------------------------------
+
+project = 'votifier-client-php'
+copyright = '2020, Manuele Vaccari'
+author = 'Manuele Vaccari'
+
+# -- General configuration ---------------------------------------------------
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+ 'sphinxcontrib.phpdomain'
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This pattern also affects html_static_path and html_extra_path.
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+
+# The master toctree document.
+master_doc = 'index'
+
+# The name of the default domain.
+primary_domain = 'php'
+
+# -- Options for HTML output -------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'sphinx_rtd_theme'
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
diff --git a/docs/index.rst b/docs/index.rst
new file mode 100644
index 0000000..02b9522
--- /dev/null
+++ b/docs/index.rst
@@ -0,0 +1,44 @@
+.. toctree::
+ :maxdepth: 2
+ :hidden:
+ :caption: First Steps
+
+ pages/first-steps/prerequisities
+
+.. toctree::
+ :maxdepth: 2
+ :hidden:
+ :caption: Getting Started
+
+ pages/getting-started/votifier
+ pages/getting-started/nuvotifier
+
+.. toctree::
+ :maxdepth: 2
+ :hidden:
+ :caption: API
+
+ pages/api/index
+
+.. toctree::
+ :maxdepth: 2
+ :hidden:
+ :caption: About votifier-client-php
+
+ pages/about/story
+ pages/about/faq
+ pages/about/changelog
+ pages/about/contributing
+ pages/about/channels
+ pages/about/code-of-conduct
+ pages/about/sponsors
+
+===============================================
+Welcome to votifier-client-php's documentation!
+===============================================
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`search`
diff --git a/docs/make.bat b/docs/make.bat
new file mode 100644
index 0000000..922152e
--- /dev/null
+++ b/docs/make.bat
@@ -0,0 +1,35 @@
+@ECHO OFF
+
+pushd %~dp0
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+ set SPHINXBUILD=sphinx-build
+)
+set SOURCEDIR=.
+set BUILDDIR=_build
+
+if "%1" == "" goto help
+
+%SPHINXBUILD% >NUL 2>NUL
+if errorlevel 9009 (
+ echo.
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+ echo.installed, then set the SPHINXBUILD environment variable to point
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
+ echo.may add the Sphinx directory to PATH.
+ echo.
+ echo.If you don't have Sphinx installed, grab it from
+ echo.http://sphinx-doc.org/
+ exit /b 1
+)
+
+%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+goto end
+
+:help
+%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+
+:end
+popd
diff --git a/docs/pages/about/changelog.rst b/docs/pages/about/changelog.rst
new file mode 100644
index 0000000..3296f8c
--- /dev/null
+++ b/docs/pages/about/changelog.rst
@@ -0,0 +1,3 @@
+=========
+Changelog
+=========
diff --git a/docs/pages/about/channels.rst b/docs/pages/about/channels.rst
new file mode 100644
index 0000000..12aeb5d
--- /dev/null
+++ b/docs/pages/about/channels.rst
@@ -0,0 +1,3 @@
+==================
+Community channels
+==================
diff --git a/docs/pages/about/code-of-conduct.rst b/docs/pages/about/code-of-conduct.rst
new file mode 100644
index 0000000..a33db7b
--- /dev/null
+++ b/docs/pages/about/code-of-conduct.rst
@@ -0,0 +1,3 @@
+===============
+Code of conduct
+===============
diff --git a/docs/pages/about/contributing.rst b/docs/pages/about/contributing.rst
new file mode 100644
index 0000000..06a5d40
--- /dev/null
+++ b/docs/pages/about/contributing.rst
@@ -0,0 +1,10 @@
+============
+Contributing
+============
+
+.. toctree::
+ :maxdepth: 2
+
+ contributing/ways-to-contribute
+ contributing/pull-request-workflow
+ contributing/code-style-guidelines
diff --git a/docs/pages/about/contributing/code-style-guidelines.rst b/docs/pages/about/contributing/code-style-guidelines.rst
new file mode 100644
index 0000000..3cbc6f4
--- /dev/null
+++ b/docs/pages/about/contributing/code-style-guidelines.rst
@@ -0,0 +1,3 @@
+=====================
+Code style guidelines
+=====================
diff --git a/docs/pages/about/contributing/pull-request-workflow.rst b/docs/pages/about/contributing/pull-request-workflow.rst
new file mode 100644
index 0000000..093d253
--- /dev/null
+++ b/docs/pages/about/contributing/pull-request-workflow.rst
@@ -0,0 +1,3 @@
+=====================
+Pull request workflow
+=====================
diff --git a/docs/pages/about/contributing/ways-to-contribute.rst b/docs/pages/about/contributing/ways-to-contribute.rst
new file mode 100644
index 0000000..982952b
--- /dev/null
+++ b/docs/pages/about/contributing/ways-to-contribute.rst
@@ -0,0 +1,3 @@
+==================
+Ways to contribute
+==================
diff --git a/docs/pages/about/faq.rst b/docs/pages/about/faq.rst
new file mode 100644
index 0000000..ebb8b81
--- /dev/null
+++ b/docs/pages/about/faq.rst
@@ -0,0 +1,3 @@
+================================
+FAQ (Frequently Asked Questions)
+================================
diff --git a/docs/pages/about/sponsors.rst b/docs/pages/about/sponsors.rst
new file mode 100644
index 0000000..2854422
--- /dev/null
+++ b/docs/pages/about/sponsors.rst
@@ -0,0 +1,3 @@
+========
+Sponsors
+========
diff --git a/docs/pages/about/story.rst b/docs/pages/about/story.rst
new file mode 100644
index 0000000..a1751a3
--- /dev/null
+++ b/docs/pages/about/story.rst
@@ -0,0 +1,3 @@
+=========
+The Story
+=========
diff --git a/docs/pages/api/Messages.rst b/docs/pages/api/Messages.rst
new file mode 100644
index 0000000..8ecd2de
--- /dev/null
+++ b/docs/pages/api/Messages.rst
@@ -0,0 +1,27 @@
+**\\D3strukt0r\\VotifierClient**
+
+========
+Messages
+========
+
+.. php:namespace:: D3strukt0r\VotifierClient
+.. php:class:: Messages
+
+ Internal use for translations.
+
+ .. php:const:: NOT_VOTIFIER
+
+ .. php:const:: NOT_SENT_PACKAGE
+
+ .. php:const:: NOT_RECEIVED_PACKAGE
+
+ .. php:const:: NUVOTIFIER_SERVER_ERROR
+
+ .. php:staticmethod:: public get($messageCode[, $language = null]) -> string
+
+ Translate and format a translation.
+
+ :param int $messageCode: (Required) The message code to identify the required resource
+ :param string $language: (Optional) The language code (e. g. en, de, es).
+
+ :return: string — Returns the message in the specified language
diff --git a/docs/pages/api/ServerConnection.rst b/docs/pages/api/ServerConnection.rst
new file mode 100644
index 0000000..5eba924
--- /dev/null
+++ b/docs/pages/api/ServerConnection.rst
@@ -0,0 +1,46 @@
+**\\D3strukt0r\\VotifierClient**
+
+================
+ServerConnection
+================
+
+.. php:namespace:: D3strukt0r\VotifierClient
+.. php:class:: ServerConnection
+
+ The class ServerConnection is used to create a connection to a server.
+
+ .. php:attr:: private $serverType
+
+ :php:class:`\\D3strukt0r\\VotifierClient\\ServerType\\ServerTypeInterface` — The server type information package
+
+ .. php:attr:: private $s
+
+ resource — The username who wants to receive the rewards
+
+ .. php:method:: public __construct($serverType)
+
+ Creates the ServerConnection object.
+
+ :param \\D3strukt0r\\VotifierClient\\ServerType\\ServerTypeInterface $serverType: (Required) The server type information package to connect to
+
+ :throws: :php:exc:`\\Exception`
+
+ .. php:method:: public __destruct()
+
+ Closes the connection when the object is destroyed.
+
+ .. php:method:: public send($string) -> bool
+
+ Sends a string to the server.
+
+ :param string $string: (Required) The string which should be sent to the server
+
+ :returns: bool — Returns true if string was sent, or false if not
+
+ .. php:method:: public receive([$length = 64]) -> string|null
+
+ Reads a string which is being received from the server.
+
+ :param int $length: (Optional) The length of the requested string
+
+ :returns: string|null — Returns the string that was received from the server
diff --git a/docs/pages/api/ServerType/ClassicVotifier.rst b/docs/pages/api/ServerType/ClassicVotifier.rst
new file mode 100644
index 0000000..f528def
--- /dev/null
+++ b/docs/pages/api/ServerType/ClassicVotifier.rst
@@ -0,0 +1,73 @@
+**\\D3strukt0r\\VotifierClient\\ServerType**
+
+===============
+ClassicVotifier
+===============
+
+.. php:namespace:: D3strukt0r\VotifierClient\ServerType
+.. php:class:: ClassicVotifier
+
+ The Class to access a server which uses the classic "Votifier" plugin.
+
+ .. php:attr:: private $host
+
+ string — The domain or ip to connect to Votifier
+
+ .. php:attr:: private $port
+
+ int — The port which votifier uses on the server
+
+ .. php:attr:: private $publicKey
+
+ string — The public.key which is generated by the plugin.
+
+ .. php:method:: public __construct($host, $port, $publicKey)
+
+ Creates the ClassicVotifier object.
+
+ :param string $host: (Required) The domain or ip to connect to Votifier
+ :param int|null $port: (Required) The port which votifier uses on the server
+ :param string $publicKey: (Required) The public.key which is generated by the plugin
+
+ .. php:method:: public getHost() -> string
+
+ Returns the host.
+
+ :returns: string — Returns the host
+
+ .. php:method:: public getPort() -> int
+
+ Returns the port.
+
+ :returns: int — Returns the port
+
+ .. php:method:: public getPublicKey() -> string
+
+ Returns the public key.
+
+ :returns: string — Returns the public key
+
+ .. php:method:: public verifyConnection($header) -> bool
+
+ Verifies that the connection is correct.
+
+ :param bool|string $header: (Required) The header that the plugin usually sends
+
+ :returns: bool — Returns true if connections is available, otherwise false
+
+ .. php:method:: public preparePackage($vote) -> string
+
+ Create encrypted package for default Votifier.
+
+ :param \\D3strukt0r\\VotifierClient\\VoteType\\VoteInterface $vote: (Required) The vote package with all the information
+
+ :returns: string — Returns the string to be sent to the server
+
+ .. php:method:: public send($connection, $vote)
+
+ Sends the vote package to the server.
+
+ :param \\D3strukt0r\\VotifierClient\\ServerConnection $connection: (Required) The connection type to the plugin
+ :param \\D3strukt0r\\VotifierClient\\VoteType\\VoteInterface $vote: (Required) The vote type package
+
+ :throws: :php:exc:`\\Exception`
diff --git a/docs/pages/api/ServerType/NuVotifier.rst b/docs/pages/api/ServerType/NuVotifier.rst
new file mode 100644
index 0000000..978dec1
--- /dev/null
+++ b/docs/pages/api/ServerType/NuVotifier.rst
@@ -0,0 +1,100 @@
+**\\D3strukt0r\\VotifierClient\\ServerType**
+
+==========
+NuVotifier
+==========
+
+.. php:namespace:: D3strukt0r\VotifierClient\ServerType
+.. php:class:: NuVotifier
+
+ The Class to access a server which uses the plugin "NuVotifier".
+
+ .. php:attr:: private $host
+
+ string — The domain or ip to connect to Votifier
+
+ .. php:attr:: private $port
+
+ int — The port which votifier uses on the server
+
+ .. php:attr:: private $publicKey
+
+ string — The public.key which is generated by the plugin.
+
+ .. php:attr:: private $protocolV2
+
+ bool — Use version 2 of the protocol
+
+ .. php:attr:: private $token
+
+ string|null — The token from the config.yml.
+
+ .. php:method:: public __construct($host, $port, $publicKey[, $protocolV2, $token])
+
+ Creates the NuVotifier object.
+
+ :param string $host: (Required) The domain or ip to connect to Votifier
+ :param int|null $port: (Required) The port which votifier uses on the server
+ :param string $publicKey: (Required) The key which is generated by the plugin. Only needed if using v1!
+ :param bool $protocolV2: (Optional) Use version 2 of the protocol (Recommended)
+ :param string|null $token: (Optional) To use version 2 protocol the token is needed from the config.yml.
+
+ :throws: :php:exc:`\\Exception`
+
+ .. php:method:: public getHost() -> string
+
+ Returns the host.
+
+ :returns: string — Returns the host
+
+ .. php:method:: public getPort() -> int
+
+ Returns the port.
+
+ :returns: int — Returns the port
+
+ .. php:method:: public getPublicKey() -> string
+
+ Returns the public key.
+
+ :returns: string — Returns the public key
+
+ .. php:method:: public isProtocolV2() -> bool
+
+ Checks whether the connection uses the version 2 protocol.
+
+ :returns: bool — Returns true, if using the new version of NuVotifier or false otherwise
+
+ .. php:method:: public verifyConnection($header) -> bool
+
+ Verifies that the connection is correct.
+
+ :param bool|string $header: (Required) The header that the plugin usually sends
+
+ :returns: bool — Returns true if connections is available, otherwise false
+
+ .. php:method:: public preparePackage($vote) -> string
+
+ Create encrypted package for default Votifier.
+
+ :param \\D3strukt0r\\VotifierClient\\VoteType\\VoteInterface $vote: (Required) The vote package with all the information
+
+ :returns: string — Returns the string to be sent to the server
+
+ .. php:method:: public preparePackageV2($vote, $challenge) -> string
+
+ Prepares the vote package to be sent as version 2 protocol package.
+
+ :param \\D3strukt0r\\VotifierClient\\VoteType\\VoteInterface $vote: (Required) The vote package with information
+ :param string $challenge: (Required) The challenge sent by the server
+
+ :returns: string — Returns the string to be sent to the server
+
+ .. php:method:: public send($connection, $vote)
+
+ Sends the vote package to the server.
+
+ :param \\D3strukt0r\\VotifierClient\\ServerConnection $connection: (Required) The connection type to the plugin
+ :param \\D3strukt0r\\VotifierClient\\VoteType\\VoteInterface $vote: (Required) The vote type package
+
+ :throws: :php:exc:`\\Exception`
diff --git a/docs/pages/api/ServerType/ServerTypeInterface.rst b/docs/pages/api/ServerType/ServerTypeInterface.rst
new file mode 100644
index 0000000..bd1f1bd
--- /dev/null
+++ b/docs/pages/api/ServerType/ServerTypeInterface.rst
@@ -0,0 +1,45 @@
+**\\D3strukt0r\\VotifierClient\\ServerType**
+
+===================
+ServerTypeInterface
+===================
+
+.. php:namespace:: D3strukt0r\VotifierClient\ServerType
+.. php:interface:: ServerTypeInterface
+
+ The interface ServerTypeInterface is used to define a PluginType on the server.
+
+ .. php:method:: public getHost() -> string
+
+ Returns the host.
+
+ :returns: string — Returns the host
+
+ .. php:method:: public getPort() -> int
+
+ Returns the port.
+
+ :returns: int — Returns the port
+
+ .. php:method:: public getPublicKey() -> string
+
+ Returns the public key.
+
+ :returns: string — Returns the public key
+
+ .. php:method:: public verifyConnection($header) -> bool
+
+ Verifies that the connection is correct.
+
+ :param bool|string $header: (Required) The header that the plugin usually sends
+
+ :returns: bool — Returns true if connections is available, otherwise false
+
+ .. php:method:: public send($connection, $vote)
+
+ Sends the vote package to the server.
+
+ :param \\D3strukt0r\\VotifierClient\\ServerConnection $connection: (Required) The connection type to the plugin
+ :param \\D3strukt0r\\VotifierClient\\VoteType\\VoteInterface $vote: (Required) The vote type package
+
+ :throws: :php:exc:`\\Exception`
diff --git a/docs/pages/api/ServerType/index.rst b/docs/pages/api/ServerType/index.rst
new file mode 100644
index 0000000..b528940
--- /dev/null
+++ b/docs/pages/api/ServerType/index.rst
@@ -0,0 +1,20 @@
+**\\D3strukt0r\\VotifierClient**
+
+============
+ServerType\\
+============
+
+**Interfaces**
+
+.. toctree::
+ :maxdepth: 1
+
+ ServerTypeInterface
+
+**Classes**
+
+.. toctree::
+ :maxdepth: 1
+
+ ClassicVotifier
+ NuVotifier
diff --git a/docs/pages/api/Vote.rst b/docs/pages/api/Vote.rst
new file mode 100644
index 0000000..4fdd4be
--- /dev/null
+++ b/docs/pages/api/Vote.rst
@@ -0,0 +1,32 @@
+**\\D3strukt0r\\VotifierClient**
+
+====
+Vote
+====
+
+.. php:namespace:: D3strukt0r\VotifierClient
+.. php:class:: Vote
+
+ This class is used for easy access to all classes and to send the votes.
+
+ .. php:attr:: private $vote
+
+ :php:class:`\\D3strukt0r\\VotifierClient\\VoteType\\VoteInterface` — The vote package
+
+ .. php:attr:: private $server
+
+ :php:class:`\\D3strukt0r\\VotifierClient\\ServerType\\ServerTypeInterface` — The server type information package
+
+ .. php:method:: public __construct($vote, $serverType)
+
+ Created a Vote object.
+
+ :param \\D3strukt0r\\VotifierClient\\VoteType\\VoteInterface $vote: (Required) The vote package
+ :param \\D3strukt0r\\VotifierClient\\ServerType\\ServerTypeInterface $serverType: (Required) The server type information package
+
+ .. php:method:: public send()
+
+ Sends the vote package to the server.
+
+ :throws: :php:exc:`\\Exception`
+
diff --git a/docs/pages/api/VoteType/ClassicVote.rst b/docs/pages/api/VoteType/ClassicVote.rst
new file mode 100644
index 0000000..5bba91c
--- /dev/null
+++ b/docs/pages/api/VoteType/ClassicVote.rst
@@ -0,0 +1,67 @@
+**\\D3strukt0r\\VotifierClient\\VoteType**
+
+===========
+ClassicVote
+===========
+
+.. php:namespace:: D3strukt0r\VotifierClient\VoteType
+.. php:class:: ClassicVote
+
+ The classic vote package can be used by most plugins.
+
+ .. php:attr:: private $serviceName
+
+ string — The name of the list/service
+
+ .. php:attr:: private $username
+
+ string — The username who wants to receive the rewards
+
+ .. php:attr:: private $address
+
+ string — The IP Address of the user
+
+ .. php:attr:: private $timestamp
+
+ \\DateTime|null — The time when the vote will be sent
+
+ .. php:method:: public __construct($username, $serviceName, $address[, $timestamp = null])
+
+ Creates the ClassicVote object.
+
+ :param string $username: (Required) The username who wants to receive the rewards
+ :param string $serviceName: (Required) The name of the list/service
+ :param string $address: (Required) The IP Address of the user
+ :param \\DateTime|null $timestamp: (Optional) The time when the vote will be sent
+
+ .. php:method:: public getServiceName() -> string
+
+ The name of the list/service.
+
+ :returns: string — Returns the name of the list/service
+
+ .. php:method:: public getUsername() -> string
+
+ The username who wants to receive the rewards.
+
+ :returns: string — Returns the username who wants to receive the rewards
+
+ .. php:method:: public getAddress() -> string
+
+ The IP Address of the user.
+
+ :returns: string — Returns the IP Address of the user
+
+ .. php:method:: public getTimestamp() -> int|null
+
+ Get the time when the vote was sent.
+
+ :returns: int|null — Returns the time when the vote was sent
+
+ .. php:method:: public setTimestamp([$timestamp = null]) -> self
+
+ Set the time when the vote will be sent.
+
+ :param \\DateTime|null $timestamp: (Optional) Either give a wanted timestamp or it will use the current time
+
+ :returns: self — Returns the class itself, for doing multiple things at once
diff --git a/docs/pages/api/VoteType/VoteInterface.rst b/docs/pages/api/VoteType/VoteInterface.rst
new file mode 100644
index 0000000..226bff3
--- /dev/null
+++ b/docs/pages/api/VoteType/VoteInterface.rst
@@ -0,0 +1,42 @@
+**\\D3strukt0r\\VotifierClient\\VoteType**
+
+=============
+VoteInterface
+=============
+
+.. php:namespace:: D3strukt0r\VotifierClient\VoteType
+.. php:interface:: VoteInterface
+
+ The interface VoteInterface will be used for different kinds of vote packages.
+
+ .. php:method:: public getServiceName() -> string
+
+ The name of the list/service.
+
+ :returns: string — Returns the name of the list/service
+
+ .. php:method:: public getUsername() -> string
+
+ The username who wants to receive the rewards.
+
+ :returns: string — Returns the username who wants to receive the rewards
+
+ .. php:method:: public getAddress() -> string
+
+ The IP Address of the user.
+
+ :returns: string — Returns the IP Address of the user
+
+ .. php:method:: public getTimestamp() -> int|null
+
+ Get the time when the vote was sent.
+
+ :returns: int|null — Returns the time when the vote was sent
+
+ .. php:method:: public setTimestamp([$timestamp = null]) -> self
+
+ Set the time when the vote will be sent.
+
+ :param \\DateTime|null $timestamp: (Optional) Either give a wanted timestamp or it will use the current time
+
+ :returns: self — Returns the class itself, for doing multiple things at once
diff --git a/docs/pages/api/VoteType/index.rst b/docs/pages/api/VoteType/index.rst
new file mode 100644
index 0000000..731721c
--- /dev/null
+++ b/docs/pages/api/VoteType/index.rst
@@ -0,0 +1,19 @@
+**\\D3strukt0r\\VotifierClient**
+
+==========
+VoteType\\
+==========
+
+**Interfaces**
+
+.. toctree::
+ :maxdepth: 1
+
+ VoteInterface
+
+**Classes**
+
+.. toctree::
+ :maxdepth: 1
+
+ ClassicVote
diff --git a/docs/pages/api/index.rst b/docs/pages/api/index.rst
new file mode 100644
index 0000000..70a23d9
--- /dev/null
+++ b/docs/pages/api/index.rst
@@ -0,0 +1,20 @@
+==============================
+\\D3strukt0r\\VotifierClient\\
+==============================
+
+**Namespaces**
+
+.. toctree::
+ :maxdepth: 1
+
+ ServerType/index
+ VoteType/index
+
+**Classes**
+
+.. toctree::
+ :maxdepth: 1
+
+ Messages
+ ServerConnection
+ Vote
diff --git a/docs/pages/first-steps/prerequisities.rst b/docs/pages/first-steps/prerequisities.rst
new file mode 100644
index 0000000..0fb9eff
--- /dev/null
+++ b/docs/pages/first-steps/prerequisities.rst
@@ -0,0 +1,60 @@
+==============
+Prerequisities
+==============
+
+What things you need to install the software and how to install them
+
+**PHP project using at least PHP 7.1)**
+
+You could for example add the requirement to the composer.json file.
+
+.. code-block:: json
+
+ {
+ "require": {
+ "php": ">=7.1"
+ }
+ }
+
+And then run
+
+.. code-block:: bash
+
+ composer require d3strukt0r/votifier-client
+
+Or add it manually to the composer.json file
+
+.. code-block:: json
+
+ {
+ "require": {
+ "php": ">=7.1",
+ "d3strukt0r/votifier-client": "^2"
+ }
+ }
+
+**Minecraft server with the Votifier plugin**
+
+You can set this up to be able to test if you website is set up correctly.
+
+We can use a Docker container for this
+
+.. code-block:: bash
+
+ docker run -it \
+ -p 25565:25565 \
+ -p 8192:8192 \
+ -v $(pwd)/data:/data \
+ -e JAVA_MAX_MEMORY=1G \
+ -e EULA=true \
+ d3strukt0r/spigot
+
+And place the latest and desired Votifier Jar that you want. Out of simplicity let's use the classic one.
+
+https://dev.bukkit.org/projects/votifier/files/latest
+
+And put it in :code:`./data/plugins/`
+
+After that you can restart the server with the previous command.
+
+Now you have your project with the plugin and a server which runs the votifier plugin.
diff --git a/docs/pages/getting-started/nuvotifier.rst b/docs/pages/getting-started/nuvotifier.rst
new file mode 100644
index 0000000..05e3510
--- /dev/null
+++ b/docs/pages/getting-started/nuvotifier.rst
@@ -0,0 +1,52 @@
+==============================
+Using a server with NuVotifier
+==============================
+
+When you have a server which runs the NuVotifier plugin, you can use this code here.
+
+For NuVotifier however, there are two ways of sending a vote package. Either the classic version, which is
+EXACTLY the same, like using the ClassicVotifier approach, or the version 2 which is special to NuVotifier.
+
+The following is the classic one, which is as mentioned, the same like ClassicVotifier:
+
+.. code-block:: php
+
+ send();
+ // Connection created, and vote sent. Doesn't mean the server handled it correctly,
+ // but the client did.
+ } catch (\Exception $exception) {
+ // Could not send Vote. Normally this happens when the client can't create a connection.
+ }
+
+To have an in-depth look at the classes and their objects, refer to the API section.
diff --git a/docs/pages/getting-started/votifier.rst b/docs/pages/getting-started/votifier.rst
new file mode 100644
index 0000000..4cedf68
--- /dev/null
+++ b/docs/pages/getting-started/votifier.rst
@@ -0,0 +1,35 @@
+============================
+Using a server with Votifier
+============================
+
+When you have a server which runs the classic Votifier plugin, you can use this code here.
+
+You can place following code whereever you want to set up the vote:
+
+.. code-block:: php
+
+ send();
+ // Connection created, and vote sent. Doesn't mean the server handled it correctly,
+ // but the client did.
+ } catch (\Exception $exception) {
+ // Could not send Vote. Normally this happens when the client can't create a connection.
+ }
+
+To have an in-depth look at the classes and their objects, refer to the API section.
diff --git a/docs/requirements.txt b/docs/requirements.txt
new file mode 100644
index 0000000..4c35754
--- /dev/null
+++ b/docs/requirements.txt
@@ -0,0 +1,2 @@
+sphinx_rtd_theme
+sphinxcontrib-phpdomain
diff --git a/src/Messages.php b/src/Messages.php
index 9599d71..175b7f2 100644
--- a/src/Messages.php
+++ b/src/Messages.php
@@ -5,9 +5,9 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient;
@@ -26,29 +26,29 @@ class Messages
/**
* Translate and format a translation.
*
- * @param int $messageCode (Required) The message code to identify the required resource
- * @param string $language (Optional) The language code (e. g. en, de, es)
+ * @param int $messageCode (Required) The message code to identify the required resource
+ * @param string|null $language (Optional) The language code (e. g. en, de, es).
*
- * @return string
+ * @return string returns the message in the specified language
*/
- public static function get(int $messageCode, string $language = 'en'): string
+ public static function get(int $messageCode, string $language = null): string
{
- $messages = array(
- 'en' => array(
+ $messages = [
+ 'en' => [
self::NOT_VOTIFIER => 'The connection does not belong to Votifier',
self::NOT_SENT_PACKAGE => 'Couldn\'t write to remote host',
self::NOT_RECEIVED_PACKAGE => 'Unable to read server response',
self::NUVOTIFIER_SERVER_ERROR => 'Votifier server error: {0}: {1}',
- ),
- );
+ ],
+ ];
$requestedMessage = $messages[$language ?: 'en'][$messageCode];
- $argsCount = func_num_args();
+ $argsCount = \func_num_args();
if ($argsCount > 2) {
$firstArg = func_get_arg(2);
- if (is_array($firstArg)) {
+ if (\is_array($firstArg)) {
foreach ($firstArg as $key => $value) {
$requestedMessage = str_replace('{'.$key.'}', $value, $requestedMessage);
}
diff --git a/src/ServerConnection.php b/src/ServerConnection.php
index d52b220..48c40e6 100644
--- a/src/ServerConnection.php
+++ b/src/ServerConnection.php
@@ -5,9 +5,9 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient;
@@ -21,12 +21,12 @@
class ServerConnection
{
/**
- * @var ServerTypeInterface The server type information package
+ * @var ServerTypeInterface the server type information package
*/
private $serverType;
/**
- * @var resource The connection to the server
+ * @var resource the connection to the server
*/
private $s;
@@ -58,11 +58,11 @@ public function __destruct()
}
/**
- * Sends a string to the server and return true if it worked or false if not.
+ * Sends a string to the server.
*
* @param string $string (Required) The string which should be sent to the server
*
- * @return bool
+ * @return bool returns true if string was sent, or false if not
*/
public function send(string $string): bool
{
@@ -80,11 +80,11 @@ public function send(string $string): bool
}
/**
- * Reads a string which is being received from the server. Returns the string.
+ * Reads a string which is being received from the server.
*
* @param int $length (Optional) The length of the requested string
*
- * @return string|null
+ * @return string|null returns the string that was received from the server
*/
public function receive(int $length = 64): ?string
{
diff --git a/src/ServerType/ClassicVotifier.php b/src/ServerType/ClassicVotifier.php
index 8eeacd5..d9138cb 100644
--- a/src/ServerType/ClassicVotifier.php
+++ b/src/ServerType/ClassicVotifier.php
@@ -5,9 +5,9 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient\ServerType;
@@ -23,17 +23,17 @@
class ClassicVotifier implements ServerTypeInterface
{
/**
- * @var string The domain or ip to connect to Votifier
+ * @var string the domain or ip to connect to Votifier
*/
private $host;
/**
- * @var int The port which votifier uses on the server
+ * @var int the port which votifier uses on the server
*/
private $port = 8192;
/**
- * @var string The public.key which is generated by the plugin
+ * @var string The public.key which is generated by the plugin.
*/
private $publicKey;
@@ -56,7 +56,7 @@ public function __construct(string $host, ?int $port, string $publicKey)
$this->publicKey = wordwrap($this->publicKey, 65, "\n", true);
$this->publicKey = <<publicKey
+{$this->publicKey}
-----END PUBLIC KEY-----
EOF;
}
@@ -87,10 +87,6 @@ public function getPublicKey(): string
/**
* {@inheritdoc}
- *
- * @param string|null $header (Required) The header that the plugin usually sends
- *
- * @return bool
*/
public function verifyConnection(?string $header): bool
{
@@ -104,9 +100,9 @@ public function verifyConnection(?string $header): bool
/**
* Create encrypted package for default Votifier.
*
- * @param VoteInterface $vote (Required) The vote package with all the information
+ * @param voteInterface $vote (Required) The vote package with all the information
*
- * @return string
+ * @return string returns the string to be sent to the server
*/
public function preparePackage(VoteInterface $vote): string
{
@@ -125,11 +121,6 @@ public function preparePackage(VoteInterface $vote): string
/**
* {@inheritdoc}
- *
- * @param ServerConnection $connection (Required) The connection type to the plugin
- * @param VoteInterface $vote (Required) The vote type package
- *
- * @throws \Exception
*/
public function send(ServerConnection $connection, VoteInterface $vote): void
{
diff --git a/src/ServerType/NuVotifier.php b/src/ServerType/NuVotifier.php
index c8117ba..5f52b5c 100644
--- a/src/ServerType/NuVotifier.php
+++ b/src/ServerType/NuVotifier.php
@@ -5,9 +5,9 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient\ServerType;
@@ -23,12 +23,12 @@
class NuVotifier extends ClassicVotifier
{
/**
- * @var bool Use version 2 of the protocol
+ * @var bool use version 2 of the protocol
*/
private $protocolV2;
/**
- * @var string|null The token from the config.yml
+ * @var string|null The token from the config.yml.
*/
private $token;
@@ -39,7 +39,7 @@ class NuVotifier extends ClassicVotifier
* @param int|null $port (Required) The port which votifier uses on the server
* @param string|null $publicKey (Required) The key which is generated by the plugin. Only needed if using v1!
* @param bool $protocolV2 (Optional) Use version 2 of the protocol (Recommended)
- * @param string|null $token (Optional) To use version 2 protocol the token is needed from the config.yml
+ * @param string|null $token (Optional) To use version 2 protocol the token is needed from the config.yml.
*
* @throws \Exception
*/
@@ -66,7 +66,7 @@ public function __construct(
/**
* Checks whether the connection uses the version 2 protocol.
*
- * @return bool
+ * @return bool returns true, if using the new version of NuVotifier or false otherwise
*/
public function isProtocolV2(): bool
{
@@ -75,15 +75,11 @@ public function isProtocolV2(): bool
/**
* {@inheritdoc}
- *
- * @param string|null $header (Required) The header that the plugin usually sends
- *
- * @return bool
*/
public function verifyConnection(?string $header): bool
{
$header_parts = explode(' ', $header);
- if (null === $header || false === mb_strpos($header, 'VOTIFIER') || 3 !== count($header_parts)) {
+ if (null === $header || false === mb_strpos($header, 'VOTIFIER') || 3 !== \count($header_parts)) {
return false;
}
@@ -96,30 +92,25 @@ public function verifyConnection(?string $header): bool
* @param VoteInterface $vote (Required) The vote package with information
* @param string $challenge (Required) The challenge sent by the server
*
- * @return string
+ * @return string returns the string to be sent to the server
*/
public function preparePackageV2(VoteInterface $vote, string $challenge): string
{
- $payloadJson = json_encode(array(
+ $payloadJson = json_encode([
'username' => $vote->getUsername(),
'serviceName' => $vote->getServiceName(),
'timestamp' => $vote->getTimestamp(),
'address' => $vote->getAddress(),
'challenge' => $challenge,
- ));
+ ]);
$signature = base64_encode(hash_hmac('sha256', $payloadJson, $this->token, true));
- $messageJson = json_encode(array('signature' => $signature, 'payload' => $payloadJson));
+ $messageJson = json_encode(['signature' => $signature, 'payload' => $payloadJson]);
return pack('nn', 0x733a, mb_strlen($messageJson)).$messageJson;
}
/**
* {@inheritdoc}
- *
- * @param ServerConnection $connection (Required) The connection type to the plugin
- * @param VoteInterface $vote (Required) The vote type package
- *
- * @throws \Exception
*/
public function send(ServerConnection $connection, VoteInterface $vote): void
{
@@ -146,7 +137,7 @@ public function send(ServerConnection $connection, VoteInterface $vote): void
$result = json_decode($response);
if ('ok' !== $result->status) {
- throw new Exception(Messages::get(Messages::NOT_RECEIVED_PACKAGE, null, $result->cause, $result->error));
+ throw new Exception(Messages::get(Messages::NUVOTIFIER_SERVER_ERROR, null, $result->cause, $result->error));
}
}
}
diff --git a/src/ServerType/ServerTypeInterface.php b/src/ServerType/ServerTypeInterface.php
index 7d64aa0..e516631 100644
--- a/src/ServerType/ServerTypeInterface.php
+++ b/src/ServerType/ServerTypeInterface.php
@@ -5,9 +5,9 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient\ServerType;
@@ -23,37 +23,37 @@ interface ServerTypeInterface
/**
* Returns the host.
*
- * @return string
+ * @return string returns the host
*/
public function getHost(): string;
/**
* Returns the port.
*
- * @return int
+ * @return int returns the port
*/
public function getPort(): int;
/**
* Returns the public key.
*
- * @return string
+ * @return string returns the public key
*/
public function getPublicKey(): string;
/**
* Verifies that the connection is correct.
*
- * @param string $header (Required) The header that the plugin usually sends
+ * @param string|null $header (Required) The header that the plugin usually sends
*
- * @return bool
+ * @return bool returns true if connections is available, otherwise false
*/
public function verifyConnection(?string $header): bool;
/**
* Sends the vote package to the server.
*
- * @param ServerConnection $connection (Required) The connection type to the plugin
+ * @param serverConnection $connection (Required) The connection type to the plugin
* @param VoteInterface $vote (Required) The vote type package
*
* @throws \Exception
diff --git a/src/Vote.php b/src/Vote.php
index c9a0693..a0f92c5 100644
--- a/src/Vote.php
+++ b/src/Vote.php
@@ -5,9 +5,9 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient;
@@ -21,12 +21,12 @@
class Vote
{
/**
- * @var \D3strukt0r\VotifierClient\VoteType\VoteInterface The vote package
+ * @var \D3strukt0r\VotifierClient\VoteType\VoteInterface the vote package
*/
private $vote;
/**
- * @var \D3strukt0r\VotifierClient\ServerType\ServerTypeInterface The server type information package
+ * @var \D3strukt0r\VotifierClient\ServerType\ServerTypeInterface the server type information package
*/
private $server;
@@ -34,7 +34,7 @@ class Vote
* Created a Vote object.
*
* @param VoteInterface $vote (Required) The vote package
- * @param ServerTypeInterface $serverType (Required) The server type information package
+ * @param serverTypeInterface $serverType (Required) The server type information package
*/
public function __construct(VoteInterface $vote, ServerTypeInterface $serverType)
{
diff --git a/src/VoteType/ClassicVote.php b/src/VoteType/ClassicVote.php
index f8f8d12..f74ddee 100644
--- a/src/VoteType/ClassicVote.php
+++ b/src/VoteType/ClassicVote.php
@@ -5,9 +5,9 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient\VoteType;
@@ -20,22 +20,22 @@
class ClassicVote implements VoteInterface
{
/**
- * @var string The name of the list/service
+ * @var string the name of the list/service
*/
private $serviceName;
/**
- * @var string The username who wants to receive the rewards
+ * @var string the username who wants to receive the rewards
*/
private $username;
/**
- * @var string The IP Address of the user
+ * @var string the IP Address of the user
*/
private $address;
/**
- * @var \DateTime|null The time when the vote will be sent
+ * @var \DateTime|null the time when the vote will be sent
*/
private $timestamp;
diff --git a/src/VoteType/VoteInterface.php b/src/VoteType/VoteInterface.php
index d5c087c..7127993 100644
--- a/src/VoteType/VoteInterface.php
+++ b/src/VoteType/VoteInterface.php
@@ -5,9 +5,9 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient\VoteType;
@@ -22,28 +22,28 @@ interface VoteInterface
/**
* The name of the list/service.
*
- * @return string
+ * @return string returns the name of the list/service
*/
public function getServiceName(): string;
/**
* The username who wants to receive the rewards.
*
- * @return string
+ * @return string returns the username who wants to receive the rewards
*/
public function getUsername(): string;
/**
* The IP Address of the user.
*
- * @return string
+ * @return string returns the IP Address of the user
*/
public function getAddress(): string;
/**
* Get the time when the vote was sent.
*
- * @return int|null
+ * @return int|null returns the time when the vote was sent
*/
public function getTimestamp(): ?int;
@@ -52,7 +52,7 @@ public function getTimestamp(): ?int;
*
* @param \DateTime|null $timestamp (Optional) Either give a wanted timestamp or it will use the current time
*
- * @return self
+ * @return self returns the class itself, for doing multiple things at once
*/
public function setTimestamp(DateTime $timestamp = null);
}
diff --git a/tests/MessagesTest.php b/tests/MessagesTest.php
index 48d96e8..bd14ccd 100644
--- a/tests/MessagesTest.php
+++ b/tests/MessagesTest.php
@@ -5,35 +5,39 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient;
use PHPUnit\Framework\TestCase;
-class MessagesTest extends TestCase
+/**
+ * @internal
+ * @coversNothing
+ */
+final class MessagesTest extends TestCase
{
/** @var \D3strukt0r\VotifierClient\Vote */
- private $obj = null;
+ private $obj;
public function testValidTranslation(): void
{
- $this->assertSame('The connection does not belong to Votifier', Messages::get(Messages::NOT_VOTIFIER));
- $this->assertSame('Couldn\'t write to remote host', Messages::get(Messages::NOT_SENT_PACKAGE));
- $this->assertSame('Unable to read server response', Messages::get(Messages::NOT_RECEIVED_PACKAGE));
- $this->assertSame('Votifier server error: {0}: {1}', Messages::get(Messages::NUVOTIFIER_SERVER_ERROR));
+ static::assertSame('The connection does not belong to Votifier', Messages::get(Messages::NOT_VOTIFIER));
+ static::assertSame('Couldn\'t write to remote host', Messages::get(Messages::NOT_SENT_PACKAGE));
+ static::assertSame('Unable to read server response', Messages::get(Messages::NOT_RECEIVED_PACKAGE));
+ static::assertSame('Votifier server error: {0}: {1}', Messages::get(Messages::NUVOTIFIER_SERVER_ERROR));
}
public function testArgs(): void
{
- $this->assertSame(
+ static::assertSame(
'Votifier server error: cause: error',
- Messages::get(Messages::NUVOTIFIER_SERVER_ERROR, 'en', array(0 => 'cause', 1 => 'error'))
+ Messages::get(Messages::NUVOTIFIER_SERVER_ERROR, 'en', [0 => 'cause', 1 => 'error'])
);
- $this->assertSame(
+ static::assertSame(
'Votifier server error: cause: error',
Messages::get(Messages::NUVOTIFIER_SERVER_ERROR, 'en', 'cause', 'error')
);
diff --git a/tests/ServerType/ClassicVotifierTest.php b/tests/ServerType/ClassicVotifierTest.php
index 5ec82ca..0893901 100644
--- a/tests/ServerType/ClassicVotifierTest.php
+++ b/tests/ServerType/ClassicVotifierTest.php
@@ -5,9 +5,9 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient\ServerType;
@@ -15,49 +15,53 @@
use D3strukt0r\VotifierClient\VoteType\ClassicVote;
use PHPUnit\Framework\TestCase;
-class ClassicVotifierTest extends TestCase
+/**
+ * @internal
+ * @coversNothing
+ */
+final class ClassicVotifierTest extends TestCase
{
/** @var \D3strukt0r\VotifierClient\ServerType\ClassicVotifier */
- private $obj = null;
+ private $obj;
private $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuyi7TXsufptucSYoVgZLonqFxtYvK0uJoxpExE+hcXRz3tR9jbXxtJ'.
'.v689/T+CHmvxJmli7g0CL0NucFDAdltat7bYu6AQMtWa7CYgvEtddwR5/ZMkZ1c3swK61fVeIsGE3oaA8Gdz1iBoG5njNmHtPzZm1CRWEYhUMMEP'.
'u9mBmqTRSYGrDr7NDJ5TL0frpLpPL/4rSTIOCJl0lBzzIT7supRmzppgeuWoh2M2lNUna329xtD5bhRPzmcIh4O2wC3jNQ+yh286mTcLG4AFBQgrS'.
'GfUHAZa6/l5rmF09Mg5CCvxqj05EBXafYGEH7bojtzDFC3J6NliAkMghk0jmrxQIDAQAB';
- public function setUp(): void
+ protected function setUp(): void
{
$this->obj = new ClassicVotifier('mock_host', 00000, $this->key);
}
- public function tearDown(): void
+ protected function tearDown(): void
{
$this->obj = null;
}
public function testInstanceOf(): void
{
- $this->assertInstanceOf('D3strukt0r\VotifierClient\ServerType\ClassicVotifier', $this->obj);
+ static::assertInstanceOf('D3strukt0r\VotifierClient\ServerType\ClassicVotifier', $this->obj);
}
public function testValues(): void
{
- $this->assertSame('mock_host', $this->obj->getHost());
- $this->assertSame(00000, $this->obj->getPort());
+ static::assertSame('mock_host', $this->obj->getHost());
+ static::assertSame(00000, $this->obj->getPort());
$key = wordwrap($this->key, 65, "\n", true);
$key = <<assertSame($key, $this->obj->getPublicKey());
+ static::assertSame($key, $this->obj->getPublicKey());
}
public function testHeaderVerification(): void
{
- $this->assertFalse($this->obj->verifyConnection(false));
- $this->assertFalse($this->obj->verifyConnection('VOTFI'));
- $this->assertTrue($this->obj->verifyConnection('VOTIFIER'));
+ static::assertFalse($this->obj->verifyConnection(false));
+ static::assertFalse($this->obj->verifyConnection('VOTFI'));
+ static::assertTrue($this->obj->verifyConnection('VOTIFIER'));
}
/*public function testPackagePreparation()
diff --git a/tests/ServerType/NuVotifierTest.php b/tests/ServerType/NuVotifierTest.php
index e978385..887f4a5 100644
--- a/tests/ServerType/NuVotifierTest.php
+++ b/tests/ServerType/NuVotifierTest.php
@@ -5,9 +5,9 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient\ServerType;
@@ -15,25 +15,29 @@
use D3strukt0r\VotifierClient\VoteType\ClassicVote;
use PHPUnit\Framework\TestCase;
-class NuVotifierTest extends TestCase
+/**
+ * @internal
+ * @coversNothing
+ */
+final class NuVotifierTest extends TestCase
{
/** @var \D3strukt0r\VotifierClient\ServerType\NuVotifier */
- private $obj = null;
+ private $obj;
/** @var \D3strukt0r\VotifierClient\ServerType\NuVotifier */
- private $obj2 = null;
+ private $obj2;
private $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuyi7TXsufptucSYoVgZLonqFxtYvK0uJoxpExE+hcXRz3tR9jbXxtJ'.
'v689/T+CHmvxJmli7g0CL0NucFDAdltat7bYu6AQMtWa7CYgvEtddwR5/ZMkZ1c3swK61fVeIsGE3oaA8Gdz1iBoG5njNmHtPzZm1CRWEYhUMMEPu'.
'9mBmqTRSYGrDr7NDJ5TL0frpLpPL/4rSTIOCJl0lBzzIT7supRmzppgeuWoh2M2lNUna329xtD5bhRPzmcIh4O2wC3jNQ+yh286mTcLG4AFBQgrSG'.
'fUHAZa6/l5rmF09Mg5CCvxqj05EBXafYGEH7bojtzDFC3J6NliAkMghk0jmrxQIDAQAB';
- public function setUp(): void
+ protected function setUp(): void
{
$this->obj = new NuVotifier('mock_host', 00000, $this->key);
$this->obj2 = new NuVotifier('mock_host', 00000, null, true, 'mock_token');
}
- public function tearDown(): void
+ protected function tearDown(): void
{
$this->obj = null;
$this->obj2 = null;
@@ -41,39 +45,39 @@ public function tearDown(): void
public function testInstanceOf(): void
{
- $this->assertInstanceOf('D3strukt0r\VotifierClient\ServerType\NuVotifier', $this->obj);
+ static::assertInstanceOf('D3strukt0r\VotifierClient\ServerType\NuVotifier', $this->obj);
}
public function testValues(): void
{
- $this->assertSame('mock_host', $this->obj->getHost());
- $this->assertSame(00000, $this->obj->getPort());
+ static::assertSame('mock_host', $this->obj->getHost());
+ static::assertSame(00000, $this->obj->getPort());
$key = wordwrap($this->key, 65, "\n", true);
$key = <<assertSame($key, $this->obj->getPublicKey());
+ static::assertSame($key, $this->obj->getPublicKey());
- $this->assertTrue($this->obj2->isProtocolV2());
+ static::assertTrue($this->obj2->isProtocolV2());
}
public function testHeaderVerification(): void
{
- $this->assertFalse($this->obj->verifyConnection(false));
- $this->assertFalse($this->obj->verifyConnection('VOTIF'));
- $this->assertTrue($this->obj->verifyConnection('VOTIFIER 2.3.7 SOMETHING'));
+ static::assertFalse($this->obj->verifyConnection(false));
+ static::assertFalse($this->obj->verifyConnection('VOTIF'));
+ static::assertTrue($this->obj->verifyConnection('VOTIFIER 2.3.7 SOMETHING'));
}
public function testPackagePreparationV2(): void
{
$testVote = new ClassicVote('mock_user', 'mock_service', 'mock_address');
$string = $this->obj->preparePackageV2($testVote, 'mock_challenge');
- $this->assertStringStartsWith('s:', $string);
+ static::assertStringStartsWith('s:', $string);
$testResultV2 = '{"signature":"LTsZweI\/1UwR+PHV9OKK0ULJRw2Ilavh17A8b6C0LBw=","payload":"{\"username\":\"mock_'.
'user\",\"serviceName\":\"mock_service\",\"timestamp\":null,\"address\":\"mock_address\",\"cha'.
'llenge\":\"mock_challenge\"}"}';
- $this->assertStringEndsWith($testResultV2, $string);
+ static::assertStringEndsWith($testResultV2, $string);
}
}
diff --git a/tests/VoteTest.php b/tests/VoteTest.php
index 3ece02f..f6a4ef5 100644
--- a/tests/VoteTest.php
+++ b/tests/VoteTest.php
@@ -5,9 +5,9 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient;
@@ -16,12 +16,16 @@
use D3strukt0r\VotifierClient\VoteType\ClassicVote;
use PHPUnit\Framework\TestCase;
-class VoteTest extends TestCase
+/**
+ * @internal
+ * @coversNothing
+ */
+final class VoteTest extends TestCase
{
/** @var \D3strukt0r\VotifierClient\Vote */
- private $obj = null;
+ private $obj;
- public function setUp(): void
+ protected function setUp(): void
{
$this->obj = new Vote(
new ClassicVote('mock_user', 'mock_service', 'mock_address'),
@@ -29,14 +33,14 @@ public function setUp(): void
);
}
- public function tearDown(): void
+ protected function tearDown(): void
{
$this->obj = null;
}
public function testInstanceOf(): void
{
- $this->assertInstanceOf('D3strukt0r\VotifierClient\Vote', $this->obj);
+ static::assertInstanceOf('D3strukt0r\VotifierClient\Vote', $this->obj);
}
/*public function testValidResult()
diff --git a/tests/VoteType/ClassicVoteTest.php b/tests/VoteType/ClassicVoteTest.php
index c49427d..4985783 100644
--- a/tests/VoteType/ClassicVoteTest.php
+++ b/tests/VoteType/ClassicVoteTest.php
@@ -5,47 +5,51 @@
*
* @package VotifierClient
* @author Manuele Vaccari
- * @copyright Copyright (c) 2017-2019 Manuele Vaccari
- * @license https://github.com/D3strukt0r/Votifier-PHP-Client/blob/master/LICENSE.md MIT License
- * @link https://github.com/D3strukt0r/Votifier-PHP-Client
+ * @copyright Copyright (c) 2017-2020 Manuele Vaccari
+ * @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
+ * @link https://github.com/D3strukt0r/votifier-client-php
*/
namespace D3strukt0r\VotifierClient\VoteType;
use PHPUnit\Framework\TestCase;
-class ClassicVoteTest extends TestCase
+/**
+ * @internal
+ * @coversNothing
+ */
+final class ClassicVoteTest extends TestCase
{
/** @var \D3strukt0r\VotifierClient\VoteType\ClassicVote */
- private $obj = null;
+ private $obj;
- public function setUp(): void
+ protected function setUp(): void
{
$this->obj = new ClassicVote('mock_user', 'mock_service', 'mock_address');
}
- public function tearDown(): void
+ protected function tearDown(): void
{
$this->obj = null;
}
public function testInstanceOf(): void
{
- $this->assertInstanceOf('D3strukt0r\VotifierClient\VoteType\ClassicVote', $this->obj);
+ static::assertInstanceOf('D3strukt0r\VotifierClient\VoteType\ClassicVote', $this->obj);
}
public function testValues(): void
{
- $this->assertSame('mock_user', $this->obj->getUsername());
- $this->assertSame('mock_service', $this->obj->getServiceName());
- $this->assertSame('mock_address', $this->obj->getAddress());
- $this->assertNull($this->obj->getTimestamp());
+ static::assertSame('mock_user', $this->obj->getUsername());
+ static::assertSame('mock_service', $this->obj->getServiceName());
+ static::assertSame('mock_address', $this->obj->getAddress());
+ static::assertNull($this->obj->getTimestamp());
}
public function testSetTimestamp(): void
{
$time = new \DateTime();
$this->obj->setTimestamp($time);
- $this->assertSame($time->getTimestamp(), $this->obj->getTimestamp());
+ static::assertSame($time->getTimestamp(), $this->obj->getTimestamp());
}
}