Class: Dev::EndOfLife::Php

Inherits:
Object show all
Defined in:
lib/firespring_dev_commands/eol/php.rb

Overview

Class which checks for eol packges referenced by the php package manager

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(php = Dev::Php.new) ⇒ Php

Returns a new instance of Php.



7
8
9
10
# File 'lib/firespring_dev_commands/eol/php.rb', line 7

def initialize(php = Dev::Php.new)
  @php = php
  @lockfile = File.join(php.local_path, "#{php.package_file.reverse.split('.')[-1].reverse}.lock")
end

Instance Attribute Details

#lockfileObject (readonly)

Returns the value of attribute lockfile.



5
6
7
# File 'lib/firespring_dev_commands/eol/php.rb', line 5

def lockfile
  @lockfile
end

#phpObject (readonly)

Returns the value of attribute php.



5
6
7
# File 'lib/firespring_dev_commands/eol/php.rb', line 5

def php
  @php
end

Instance Method Details

#composer_productsObject

1.) Parse the composer lock file 2.) Do some package name and version manipulation 3.) Return the product if it looks like something that the EOL library tracks



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/firespring_dev_commands/eol/php.rb', line 20

def composer_products
  eol = Dev::EndOfLife.new
  major_version_only_products = ['laravel']
  laravel_products = ['laravel/framework']
  symfony_products = ['symfony/http-client', 'symfony/mailer', 'symfony/mailchimp-mailer']

  [].tap do |ary|
    packages = JSON.parse(File.read(lockfile))&.fetch('packages', [])
    packages&.each do |package|
      name = package['name']
      product = if laravel_products.include?(name)
                  'laravel'
                elsif symfony_products.include?(name)
                  'symfony'
                else
                  name
                end

      # Make sure what we found is supported by the EOL library
      next unless eol.product?(product)

      version = package['version'].reverse.split('.')[-2..].join('.').reverse.tr('v', '')
      version = version.split('.').first if major_version_only_products.include?(product)
      version.chop! if version.end_with?('.00')
      ary << Dev::EndOfLife::ProductVersion.new(product, version, name)
    end
  end
end

#default_productsObject

Default to Composer products



13
14
15
# File 'lib/firespring_dev_commands/eol/php.rb', line 13

def default_products
  composer_products
end