Skip to content

Version 4.0.0

Choose a tag to compare

@DariusIII DariusIII released this 24 Feb 10:43
· 8 commits to main since this release

Release v4.0.0

Project structure & namespaces:

  • Modernized project to PSR-4 standard — source files moved from NNTP/ to src/
  • Added PHP namespaces: Net\NNTP, Net\NNTP\Protocol
  • Renamed classes from PEAR underscore style to namespaced short names:
    • Net_NNTP_Client → Net\NNTP\Client
    • Net_NNTP_Error → Net\NNTP\Error
    • Net_NNTP_Protocol_Client → Net\NNTP\Protocol\Client
  • Updated composer.json autoload from classmap to PSR-4 ("Net\\NNTP\\": "src/")
  • Added files autoload entry for Responsecode.php global constants
  • Removed all require_once includes from source files (now handled by Composer autoload)
  • Removed old NNTP/ directory

PEAR removal:

  • Removed all PEAR dependencies, code, and references
  • Removed PEAR_LOG_DEBUG constant and all _isMasked() calls from Protocol\Client
  • Replaced all PEAR::isError() calls with \Net\NNTP\Error::isError() throughout
  • Removed require_once "Log.php" and require_once "PEAR.php" from demo files
  • Removed grabPearErrors() / PEAR::setErrorHandling() from demo
  • Removed PEAR_Error references from Error class
  • Updated X-poster mail header: removed PEAR:: prefix
  • Replaced all @link http://pear.php.net/package/Net_NNTP with GitHub URL

PSR-3 logging:

  • Added psr/log as a dependency — the library now accepts any PSR-3 compatible logger
  • Type-hinted $_logger property and setLogger() parameter with Psr\Log\LoggerInterface
  • Made setLogger() public (was protected)
  • Removed deprecated setDebug() method from Protocol\Client
  • Updated demo Logger class to extend Psr\Log\AbstractLogger

Configuration:

  • Added vlucas/phpdotenv as a dependency for demo configuration
  • Replaced hardcoded config.inc.php with .env-based configuration using phpdotenv
  • Added .env.example with all available settings and documented defaults
  • Added .env to .gitignore

Test suite:

  • Added comprehensive PHPUnit 13 test suite (117 tests, 253 assertions):
    • tests/Unit/ErrorTest.php — Error class construction, isError(), toString
    • tests/Unit/ClientTest.php — Client instantiation, PSR-3 logger, public API surface
    • tests/Unit/ProtocolClientTest.php — Protocol layer, throwError, _isConnected, _clearOpensslErrors
    • tests/Unit/ResponsecodeTest.php — All 48 NNTP response code constants
    • tests/Unit/AutoloadTest.php — PSR-4 autoloading, namespaces, dependency wiring
    • tests/Unit/ConfigTest.php — .env.example completeness, phpdotenv integration
    • tests/Integration/ServerConnectionTest.php — Live server: connect, groups, articles, overview, disconnect
  • Updated phpunit.xml with separate Unit and Integration test suites
  • Updated demo and phpdoc examples to use namespaced classes

Enums & code optimization:

  • Created Net\NNTP\Protocol\ResponseCode int-backed enum with all 53 NNTP response codes
    • Each case includes a description() method returning the RFC description
    • Supports ResponseCode::from(int) and ResponseCode::tryFrom(int) natively
    • Added 6 new codes not previously defined: DisconnectingRequested (205), DisconnectingForced (400), TlsContinue (382), TlsRefused (580), XgtitleFollows (282), XgtitleUnavailable (481)
  • Converted Responsecode.php to a backwards-compatible shim — all define() constants now delegate to ResponseCode::CASE->value
  • Replaced all NET_NNTP_PROTOCOL_RESPONSECODE_* references in Protocol\Client with ResponseCode::CASE->value
  • Replaced all bare integer response codes (205, 382, 400, 502, 503, etc.) with enum references
  • Converted all switch blocks to match expressions throughout Protocol\Client and Client
  • Removed all unreachable break statements after return (~50+ instances)
  • Removed dead code: if (false) { ... } block, die() calls, unused namespace-level constants
  • Removed all vim modelines, {{{ }}} fold markers, and "Local variables" blocks from all source files
  • Added declare(strict_types=1) to all source files
  • Applied constructor property promotion with readonly to Error class
  • Refactored duplicated parsing logic in Protocol\Client into private helper methods:
    _parseGroupSelected(), _parseArticlePointer(), _fetchTextAndLog(), _parseGroupLines(),
    _parseOverviewResponse(), _parseKeyValueResponse(), _parseOverviewFormat(),
    _parseNewsgroupDescriptions(), _logAndReturn(), _handleTlsNegotiation()
  • Extracted _resolveTimestamp() helper in Client to deduplicate time parsing
  • Used str_ends_with() / str_starts_with() instead of substr() comparisons
  • Used null coalescing assignment (??=) throughout
  • Used nullsafe operator (?->) consistently for logger calls
  • Used union types for _sendArticle(string|array) parameter
  • Expanded test suite to 335 tests / 526 assertions (was 117 / 253):
    • Added enum tests: case values, from(), tryFrom(), description(), int-backed verification
    • Added legacy constant shim verification
    • Added ResponseCode autoload and namespace tests

Static analysis:

  • Added PHPStan (phpstan/phpstan) as a dev dependency
  • Created phpstan.neon configuration at level 8 (strict)
  • All source files pass PHPStan level 8 with zero errors
  • Added proper type annotations (PHPDoc @return, @param) to all methods throughout Protocol\Client and Client
  • Typed all deprecated method parameters and return types (getArticleRaw(), getHeaderRaw(), etc.)
  • Changed getArticle(), getHeader(), getBody() $implode parameter from bool to mixed for v1.1 API backward compatibility
  • Added @var PHPDoc annotations to all class properties
  • Added .phpstan-cache/ to .gitignore
  • Added composer scripts: composer analyse, composer test, composer check